blob: 87fd2dad316ce57f3f204840f5ad0c36c4b07cd4 [file] [log] [blame]
David Blaikie9b29f4f2012-10-16 18:53:14 +00001// RUN: %clang_cc1 -Wno-int-to-pointer-cast -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.
Richard Smithb9c62612012-07-30 21:30:52 +000025 int fd(T(a)); // expected-warning {{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
26 T(*d)(int(p)); // expected-note {{previous}}
27 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();
Richard Smithd64effc2012-07-30 21:42:05 +000052void func2(short);
Richard Smith7984de32012-01-12 23:53:29 +000053namespace N {
Richard Smithf0375412012-01-13 02:14:39 +000054 struct S;
55
Richard Smith7984de32012-01-12 23:53:29 +000056 void emptyParens() {
57 RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}}
58 int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}}
59 func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smithf0375412012-01-13 02:14:39 +000060
61 S s(); // expected-warning {{function declaration}}
Richard Smith7984de32012-01-12 23:53:29 +000062 }
Richard Smithd64effc2012-07-30 21:42:05 +000063 void nonEmptyParens() {
64 int f = 0, // g = 0; expected-note {{change this ',' to a ';' to call 'func2'}}
65 func2(short(f)); // expected-warning {{function declaration}} expected-note {{add a pair of parentheses}}
66 }
Richard Smith7984de32012-01-12 23:53:29 +000067}
68
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000069class C { };
Douglas Gregorfa047642009-02-04 00:32:51 +000070void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000071 // not: void fn(int C);
72int g(C);
73
74void foo() {
Douglas Gregorfa047642009-02-04 00:32:51 +000075 fn(1); // expected-error {{no matching function}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000076 fn(g); // OK
77}
Kaelyn Uhrain12f32972012-05-02 00:11:40 +000078
79namespace PR11874 {
80void foo(); // expected-note 3 {{class 'foo' is hidden by a non-type declaration of 'foo' here}}
81class foo {};
82class bar {
83 bar() {
84 const foo* f1 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
85 foo* f2 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
86 foo f3; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
87 }
88};
89
90int baz; // expected-note 2 {{class 'baz' is hidden by a non-type declaration of 'baz' here}}
91class baz {};
92void fizbin() {
93 const baz* b1 = 0; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
94 baz* b2; // expected-error {{use of undeclared identifier 'b2'}}
95 baz b3; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
96}
97}