blob: 8164b2bc91e72293ec129d7bfe6db2bfc031ebb8 [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 Kyrtzidis99e9fe02013-05-07 19:54:28 +00002// RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -x objective-c++ %s
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00003
4void f() {
5 int a;
6 struct S { int m; };
7 typedef S *T;
8
9 // Expressions.
10 T(a)->m = 7;
John McCallf6a16482010-12-04 03:47:34 +000011 int(a)++; // expected-error {{assignment to cast is illegal}}
12 __extension__ int(a)++; // expected-error {{assignment to cast is illegal}}
Douglas Gregor19311e72010-09-08 21:40:08 +000013 __typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}}
John McCall0faede62010-03-12 07:11:26 +000014 void(a), ++a;
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +000015 if (int(a)+1) {}
Argyrios Kyrtzidis1b2ad2f2010-09-19 23:03:35 +000016 for (int(a)+1;;) {} // expected-warning {{expression result unused}}
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +000017 a = sizeof(int()+1);
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000018 a = sizeof(int(1));
Eli Friedman2962f4d2009-04-28 03:59:15 +000019 typeof(int()+1) a2; // expected-error {{extension used}}
Argyrios Kyrtzidis1b2ad2f2010-09-19 23:03:35 +000020 (int(1)); // expected-warning {{expression result unused}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000021
22 // type-id
Sebastian Redl9cc11e72009-07-25 15:41:38 +000023 (int())1; // expected-error {{C-style cast from 'int' to 'int ()' is not allowed}}
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000024
25 // Declarations.
Richard Smithb9c62612012-07-30 21:30:52 +000026 int fd(T(a)); // expected-warning {{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
27 T(*d)(int(p)); // expected-note {{previous}}
28 typedef T td(int(p));
29 extern T tp(int(p));
Richard Smith7984de32012-01-12 23:53:29 +000030 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 +000031 T d3v(void);
Richard Smith2f0e88a2012-01-06 02:30:50 +000032 typedef T d3t();
33 extern T f3();
Richard Smith7984de32012-01-12 23:53:29 +000034 __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 +000035 typedef void *V;
36 __typeof(*V()) f5();
37 T multi1,
Richard Smith7984de32012-01-12 23:53:29 +000038 multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
Douglas Gregor3eb1c542008-12-17 16:19:15 +000039 T(d)[5]; // expected-error {{redefinition of 'd'}}
Eli Friedman2962f4d2009-04-28 03:59:15 +000040 typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}}
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000041 void(b)(int);
Richard Smithcb7709c2012-01-05 04:12:21 +000042 int(d2) __attribute__(());
Argyrios Kyrtzidisca35baa2008-10-05 15:19:49 +000043 if (int(a)=1) {}
Douglas Gregor3eb1c542008-12-17 16:19:15 +000044 int(d3(int()));
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000045}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000046
Richard Smith7984de32012-01-12 23:53:29 +000047struct RAII {
48 RAII();
49 ~RAII();
50};
51
52void func();
Richard Smithd64effc2012-07-30 21:42:05 +000053void func2(short);
Richard Smith7984de32012-01-12 23:53:29 +000054namespace N {
Richard Smithf0375412012-01-13 02:14:39 +000055 struct S;
56
Richard Smith7984de32012-01-12 23:53:29 +000057 void emptyParens() {
58 RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}}
59 int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}}
60 func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smithf0375412012-01-13 02:14:39 +000061
62 S s(); // expected-warning {{function declaration}}
Richard Smith7984de32012-01-12 23:53:29 +000063 }
Richard Smithd64effc2012-07-30 21:42:05 +000064 void nonEmptyParens() {
65 int f = 0, // g = 0; expected-note {{change this ',' to a ';' to call 'func2'}}
66 func2(short(f)); // expected-warning {{function declaration}} expected-note {{add a pair of parentheses}}
67 }
Richard Smith7984de32012-01-12 23:53:29 +000068}
69
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000070class C { };
Douglas Gregorfa047642009-02-04 00:32:51 +000071void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000072 // not: void fn(int C);
73int g(C);
74
75void foo() {
Douglas Gregorfa047642009-02-04 00:32:51 +000076 fn(1); // expected-error {{no matching function}}
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +000077 fn(g); // OK
78}
Kaelyn Uhrain12f32972012-05-02 00:11:40 +000079
80namespace PR11874 {
81void foo(); // expected-note 3 {{class 'foo' is hidden by a non-type declaration of 'foo' here}}
82class foo {};
83class bar {
84 bar() {
85 const foo* f1 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
86 foo* f2 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
87 foo f3; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
88 }
89};
90
91int baz; // expected-note 2 {{class 'baz' is hidden by a non-type declaration of 'baz' here}}
92class baz {};
93void fizbin() {
94 const baz* b1 = 0; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
95 baz* b2; // expected-error {{use of undeclared identifier 'b2'}}
96 baz b3; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
97}
98}