blob: 6f4d08cc686cbf4be9ccfc12bfae0736b95850c9 [file] [log] [blame]
Richard Smithcb7709c2012-01-05 04:12:21 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00002
3void f() {
4 int a;
5 struct S { int m; };
6 typedef S *T;
7
8 // Expressions.
9 T(a)->m = 7;
John McCallf6a16482010-12-04 03:47:34 +000010 int(a)++; // expected-error {{assignment to cast is illegal}}
11 __extension__ int(a)++; // expected-error {{assignment to cast is illegal}}
Douglas Gregor19311e72010-09-08 21:40:08 +000012 __typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}}
John McCall0faede62010-03-12 07:11:26 +000013 void(a), ++a;
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +000014 if (int(a)+1) {}
Argyrios Kyrtzidis1b2ad2f2010-09-19 23:03:35 +000015 for (int(a)+1;;) {} // expected-warning {{expression result unused}}
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +000016 a = sizeof(int()+1);
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000017 a = sizeof(int(1));
Eli Friedman2962f4d2009-04-28 03:59:15 +000018 typeof(int()+1) a2; // expected-error {{extension used}}
Argyrios Kyrtzidis1b2ad2f2010-09-19 23:03:35 +000019 (int(1)); // expected-warning {{expression result unused}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000020
21 // type-id
Sebastian Redl9cc11e72009-07-25 15:41:38 +000022 (int())1; // expected-error {{C-style cast from 'int' to 'int ()' is not allowed}}
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000023
24 // Declarations.
Argyrios Kyrtzidis259b0d92008-10-15 23:21:32 +000025 int fd(T(a)); // expected-warning {{parentheses were disambiguated as a function declarator}}
Douglas Gregor3eb1c542008-12-17 16:19:15 +000026 T(*d)(int(p)); // expected-warning {{parentheses were disambiguated as a function declarator}} expected-note {{previous definition is here}}
Richard Smithcb7709c2012-01-05 04:12:21 +000027 typedef T(*td)(int(p));
28 extern T(*tp)(int(p));
Richard Smith7984de32012-01-12 23:53:29 +000029 T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smith80a5b272012-01-09 18:30:34 +000030 T d3v(void);
Richard Smith2f0e88a2012-01-06 02:30:50 +000031 typedef T d3t();
32 extern T f3();
Richard Smith7984de32012-01-12 23:53:29 +000033 __typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smith80a5b272012-01-09 18:30:34 +000034 typedef void *V;
35 __typeof(*V()) f5();
36 T multi1,
Richard Smith7984de32012-01-12 23:53:29 +000037 multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
Douglas Gregor3eb1c542008-12-17 16:19:15 +000038 T(d)[5]; // expected-error {{redefinition of 'd'}}
Eli Friedman2962f4d2009-04-28 03:59:15 +000039 typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}}
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000040 void(b)(int);
Richard Smithcb7709c2012-01-05 04:12:21 +000041 int(d2) __attribute__(());
Argyrios Kyrtzidisca35baa2008-10-05 15:19:49 +000042 if (int(a)=1) {}
Douglas Gregor3eb1c542008-12-17 16:19:15 +000043 int(d3(int()));
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000044}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000045
Richard Smith7984de32012-01-12 23:53:29 +000046struct RAII {
47 RAII();
48 ~RAII();
49};
50
51void func();
52namespace N {
Richard Smithf0375412012-01-13 02:14:39 +000053 struct S;
54
Richard Smith7984de32012-01-12 23:53:29 +000055 void emptyParens() {
56 RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}}
57 int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}}
58 func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smithf0375412012-01-13 02:14:39 +000059
60 S s(); // expected-warning {{function declaration}}
Richard Smith7984de32012-01-12 23:53:29 +000061 }
62}
63
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000064class C { };
Douglas Gregorfa047642009-02-04 00:32:51 +000065void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000066 // not: void fn(int C);
67int g(C);
68
69void foo() {
Douglas Gregorfa047642009-02-04 00:32:51 +000070 fn(1); // expected-error {{no matching function}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000071 fn(g); // OK
72}