
(This relands 59337263ab45d7657e and makes sure comma operator diagnostics are suppressed in a SFINAE context.) While at it, add the diagnosis message "left operand of comma operator has no effect" (used by GCC) for comma operator. This also makes Clang diagnose in the constant evaluation context which aligns with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96) Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D103938
45 lines
1.5 KiB
C++
45 lines
1.5 KiB
C++
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
struct X {
|
|
template<typename T, typename U>
|
|
static void f(int, int);
|
|
};
|
|
|
|
void f() {
|
|
void (*ptr)(int, int) = &X::f<int, int>;
|
|
|
|
unknown *p = 0; // expected-error {{unknown type name 'unknown'}}
|
|
unknown * p + 0; // expected-error {{undeclared identifier 'unknown'}}
|
|
}
|
|
|
|
auto (*p)() -> int(nullptr);
|
|
auto (*q)() -> int(*)(unknown); // expected-error {{unknown type name 'unknown'}}
|
|
auto (*r)() -> int(*)(unknown + 1); // expected-error {{undeclared identifier 'unknown'}}
|
|
|
|
int f(unknown const x); // expected-error {{unknown type name 'unknown'}}
|
|
|
|
// Disambiguating an array declarator from an array subscripting.
|
|
void arr() {
|
|
int x[] = {1}; // expected-note 2{{previous}}
|
|
|
|
// This is array indexing not an array declarator because a comma expression
|
|
// is not syntactically a constant-expression.
|
|
int(x[1,1]); // expected-warning {{left operand of comma operator has no effect}} expected-warning {{unused}}
|
|
|
|
// This is array indexing not an array declaration because a braced-init-list
|
|
// is not syntactically a constant-expression.
|
|
int(x[{0}]); // expected-error {{array subscript is not an integer}}
|
|
struct A {
|
|
struct Q { int n; };
|
|
int operator[](Q);
|
|
} a;
|
|
int(a[{0}]); // expected-warning {{unused}}
|
|
|
|
// These are array declarations.
|
|
int(x[((void)1,1)]); // expected-error {{redefinition}}
|
|
int(x[true ? 1 : (1,1)]); // expected-error {{redefinition}} // expected-warning {{left operand of comma operator has no effect}}
|
|
|
|
int (*_Atomic atomic_ptr_to_int);
|
|
*atomic_ptr_to_int = 42;
|
|
}
|