| 1 |
// RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors %s |
| 2 |
// RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -std=gnu++98 %s |
| 3 |
// RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -std=gnu++11 %s |
| 4 |
// RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -x objective-c++ %s |
| 5 |
|
| 6 |
void f() { |
| 7 |
int a; |
| 8 |
struct S { int m; }; |
| 9 |
typedef S *T; |
| 10 |
|
| 11 |
// Expressions. |
| 12 |
T(a)->m = 7; |
| 13 |
int(a)++; // expected-error {{assignment to cast is illegal}} |
| 14 |
__extension__ int(a)++; // expected-error {{assignment to cast is illegal}} |
| 15 |
__typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}} expected-warning {{expression result unused}} |
| 16 |
void(a), ++a; |
| 17 |
if (int(a)+1) {} |
| 18 |
for (int(a)+1;;) {} // expected-warning {{expression result unused}} |
| 19 |
a = sizeof(int()+1); |
| 20 |
a = sizeof(int(1)); |
| 21 |
typeof(int()+1) a2; // expected-error {{extension used}} |
| 22 |
(int(1)); // expected-warning {{expression result unused}} |
| 23 |
|
| 24 |
// type-id |
| 25 |
(int())1; // expected-error {{C-style cast from 'int' to 'int ()' is not allowed}} |
| 26 |
|
| 27 |
// Declarations. |
| 28 |
int fd(T(a)); // expected-warning {{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}} |
| 29 |
T(*d)(int(p)); // expected-note {{previous}} |
| 30 |
typedef T td(int(p)); |
| 31 |
extern T tp(int(p)); |
| 32 |
T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} |
| 33 |
T d3v(void); |
| 34 |
typedef T d3t(); |
| 35 |
extern T f3(); |
| 36 |
__typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} |
| 37 |
typedef void *V; |
| 38 |
__typeof(*V()) f5(); // expected-error {{indirection not permitted on operand of type 'V' (aka 'void *')}} |
| 39 |
T multi1, |
| 40 |
multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} |
| 41 |
T(d)[5]; // expected-error {{redefinition of 'd'}} |
| 42 |
typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}} |
| 43 |
void(b)(int); |
| 44 |
int(d2) __attribute__(()); |
| 45 |
if (int(a)=1) {} |
| 46 |
int(d3(int())); |
| 47 |
} |
| 48 |
|
| 49 |
struct RAII { |
| 50 |
RAII(); |
| 51 |
RAII(int); |
| 52 |
~RAII(); |
| 53 |
}; |
| 54 |
|
| 55 |
struct NotRAII { |
| 56 |
NotRAII(); |
| 57 |
NotRAII(int); |
| 58 |
}; |
| 59 |
|
| 60 |
void func(); |
| 61 |
void func2(short); |
| 62 |
namespace N { |
| 63 |
struct S; |
| 64 |
int n; |
| 65 |
|
| 66 |
void emptyParens() { |
| 67 |
RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}} |
| 68 |
int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}} |
| 69 |
func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 70 |
|
| 71 |
S s(); // expected-warning {{function declaration}} |
| 72 |
#if __cplusplus >= 201103L |
| 73 |
// expected-note@-2 {{replace parentheses with an initializer to declare a variable}} |
| 74 |
#endif |
| 75 |
} |
| 76 |
void nonEmptyParens() { |
| 77 |
int f = 0, // g = 0; expected-note {{change this ',' to a ';' to call 'func2'}} |
| 78 |
func2(short(f)); // expected-warning {{function declaration}} expected-note {{add a pair of parentheses}} |
| 79 |
|
| 80 |
RAII(n); // expected-warning {{parentheses were disambiguated as redundant parentheses around declaration of variable named 'n'}} |
| 81 |
// expected-note@-1 {{add a variable name to declare a 'RAII' initialized with 'n'}} |
| 82 |
// expected-note@-2 {{add enclosing parentheses to perform a function-style cast}} |
| 83 |
// expected-note@-3 {{remove parentheses to silence this warning}} |
| 84 |
|
| 85 |
RAII(undeclared1); |
| 86 |
#pragma clang diagnostic push |
| 87 |
#pragma clang diagnostic warning "-Wredundant-parens" |
| 88 |
RAII(undeclared2); // expected-warning {{redundant parentheses surrounding declarator}} |
| 89 |
#pragma clang diagnostic pop |
| 90 |
|
| 91 |
{ |
| 92 |
NotRAII(n); // expected-warning {{parentheses were disambiguated as redundant parentheses around declaration of variable named 'n'}} |
| 93 |
// expected-note@-1 {{add enclosing parentheses to perform a function-style cast}} |
| 94 |
// expected-note@-2 {{remove parentheses to silence this warning}} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
class C { }; |
| 100 |
void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}} |
| 101 |
// not: void fn(int C); |
| 102 |
int g(C); |
| 103 |
|
| 104 |
void foo() { |
| 105 |
fn(1); // expected-error {{no matching function}} |
| 106 |
fn(g); // OK |
| 107 |
} |
| 108 |
|
| 109 |
namespace PR11874 { |
| 110 |
void foo(); // expected-note 3 {{class 'foo' is hidden by a non-type declaration of 'foo' here}} |
| 111 |
class foo {}; |
| 112 |
class bar { |
| 113 |
bar() { |
| 114 |
const foo* f1 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}} |
| 115 |
foo* f2 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}} |
| 116 |
foo f3; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}} |
| 117 |
} |
| 118 |
}; |
| 119 |
|
| 120 |
int baz; // expected-note 2 {{class 'baz' is hidden by a non-type declaration of 'baz' here}} |
| 121 |
class baz {}; |
| 122 |
void fizbin() { |
| 123 |
const baz* b1 = 0; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}} |
| 124 |
baz* b2; // expected-error {{use of undeclared identifier 'b2'}} |
| 125 |
baz b3; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
namespace TemporaryFromFunctionCall { |
| 130 |
struct A { |
| 131 |
A(int); |
| 132 |
}; |
| 133 |
int f(); |
| 134 |
int g(int); |
| 135 |
namespace N { |
| 136 |
void x() { |
| 137 |
// FIXME: For the first and second of these (but not the third), we |
| 138 |
// should produce a vexing-parse warning. |
| 139 |
A(f()); |
| 140 |
A(g(int())); |
| 141 |
A(g(int)); |
| 142 |
} |
| 143 |
} |
| 144 |
} |