Home | History | Annotate | Download | only in SemaCXX
      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}}
     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 {{ISO C++ does not allow indirection 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();
     52 };
     53 
     54 void func();
     55 void func2(short);
     56 namespace N {
     57   struct S;
     58 
     59   void emptyParens() {
     60     RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}}
     61     int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}}
     62     func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
     63 
     64     S s(); // expected-warning {{function declaration}}
     65 #if __cplusplus >= 201103L
     66     // expected-note@-2 {{replace parentheses with an initializer to declare a variable}}
     67 #endif
     68   }
     69   void nonEmptyParens() {
     70     int f = 0, // g = 0; expected-note {{change this ',' to a ';' to call 'func2'}}
     71     func2(short(f)); // expected-warning {{function declaration}} expected-note {{add a pair of parentheses}}
     72   }
     73 }
     74 
     75 class C { };
     76 void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}}
     77                     // not: void fn(int C);
     78 int g(C);
     79 
     80 void foo() {
     81   fn(1); // expected-error {{no matching function}}
     82   fn(g); // OK
     83 }
     84 
     85 namespace PR11874 {
     86 void foo(); // expected-note 3 {{class 'foo' is hidden by a non-type declaration of 'foo' here}}
     87 class foo {};
     88 class bar {
     89   bar() {
     90     const foo* f1 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
     91     foo* f2 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
     92     foo f3; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
     93   }
     94 };
     95 
     96 int baz; // expected-note 2 {{class 'baz' is hidden by a non-type declaration of 'baz' here}}
     97 class baz {};
     98 void fizbin() {
     99   const baz* b1 = 0; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
    100   baz* b2; // expected-error {{use of undeclared identifier 'b2'}}
    101   baz b3; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
    102 }
    103 }
    104