Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
      2 // RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
      3 class X; // expected-note 2{{here}}
      4 typedef struct X * X_t; // expected-warning{{previously declared}}
      5 union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
      6 
      7 template<typename T> struct Y; // expected-note{{did you mean class here?}}
      8 template<class U> class Y { }; // expected-warning{{previously declared}}
      9 
     10 class A;
     11 class A;  // expected-note{{previous use is here}}
     12 struct A;  // expected-warning{{struct 'A' was previously declared as a class}}
     13 
     14 class B;  // expected-note{{did you mean struct here?}}
     15 class B;  // expected-note{{previous use is here}}\
     16           // expected-note{{did you mean struct here?}}
     17 struct B;  // expected-warning{{struct 'B' was previously declared as a class}}
     18 struct B {};  // expected-warning{{'B' defined as a struct here but previously declared as a class}}
     19 
     20 class C;  // expected-note{{previous use is here}}
     21 struct C;  // expected-warning{{struct 'C' was previously declared as a class}}\
     22            // expected-note{{previous use is here}}\
     23            // expected-note{{did you mean class here?}}
     24 class C;  // expected-warning{{class 'C' was previously declared as a struct}}\
     25           // expected-note{{previous use is here}}
     26 struct C;  // expected-warning{{struct 'C' was previously declared as a class}}\
     27            // expected-note{{did you mean class here?}}
     28 class C {};  // expected-warning{{'C' defined as a class here but previously declared as a struct}}
     29 
     30 struct D {};  // expected-note{{previous definition is here}}\
     31               // expected-note{{previous use is here}}
     32 class D {};  // expected-error{{redefinition of 'D'}}
     33 struct D;
     34 class D;  // expected-warning{{class 'D' was previously declared as a struct}}\
     35           // expected-note{{did you mean struct here?}}
     36 
     37 class E;
     38 class E;
     39 class E {};
     40 class E;
     41 
     42 struct F;
     43 struct F;
     44 struct F {};
     45 struct F;
     46 
     47 template<class U> class G;  // expected-note{{previous use is here}}\
     48                             // expected-note{{did you mean struct here?}}
     49 template<class U> struct G;  // expected-warning{{struct template 'G' was previously declared as a class template}}
     50 template<class U> struct G {};  // expected-warning{{'G' defined as a struct template here but previously declared as a class template}}
     51 
     52 /*
     53 *** 'X' messages ***
     54 CHECK: warning: struct 'X' was previously declared as a class
     55 CHECK: {{^}}typedef struct X * X_t;
     56 CHECK: {{^}}        ^{{$}}
     57 CHECK: note: previous use is here
     58 CHECK: {{^}}class X;
     59 CHECK: {{^}}      ^{{$}}
     60 CHECK: error: use of 'X' with tag type that does not match previous declaration
     61 CHECK: {{^}}union X { int x; float y; };
     62 CHECK: {{^}}^~~~~{{$}}
     63 CHECK: {{^}}class{{$}}
     64 CHECK: note: previous use is here
     65 CHECK: {{^}}class X;
     66 CHECK: {{^}}      ^{{$}}
     67 *** 'Y' messages ***
     68 CHECK: warning: 'Y' defined as a class template here but
     69       previously declared as a struct template
     70 CHECK: {{^}}template<class U> class Y { };
     71 CHECK: {{^}}                  ^{{$}}
     72 CHECK: note: did you mean class here?
     73 CHECK: {{^}}template<typename T> struct Y;
     74 CHECK: {{^}}                     ^~~~~~{{$}}
     75 CHECK: {{^}}                     class{{$}}
     76 *** 'A' messages ***
     77 CHECK: warning: struct 'A' was previously declared as a class
     78 CHECK: {{^}}struct A;
     79 CHECK: {{^}}^{{$}}
     80 CHECK: note: previous use is here
     81 CHECK: {{^}}class A;
     82 CHECK: {{^}}      ^{{$}}
     83 *** 'B' messages ***
     84 CHECK: warning: struct 'B' was previously declared as a class
     85 CHECK: {{^}}struct B;
     86 CHECK: {{^}}^{{$}}
     87 CHECK: note: previous use is here
     88 CHECK: {{^}}class B;
     89 CHECK: {{^}}      ^{{$}}
     90 CHECK: 'B' defined as a struct here but previously declared as a class
     91 CHECK: {{^}}struct B {};
     92 CHECK: {{^}}^{{$}}
     93 CHECK: note: did you mean struct here?
     94 CHECK: {{^}}class B;
     95 CHECK: {{^}}^~~~~{{$}}
     96 CHECK: {{^}}struct{{$}}
     97 CHECK: note: did you mean struct here?
     98 CHECK: {{^}}class B;
     99 CHECK: {{^}}^~~~~{{$}}
    100 CHECK: {{^}}struct{{$}}
    101 *** 'C' messages ***
    102 CHECK: warning: struct 'C' was previously declared as a class
    103 CHECK: {{^}}struct C;
    104 CHECK: {{^}}^{{$}}
    105 CHECK: note: previous use is here
    106 CHECK: {{^}}class C;
    107 CHECK: {{^}}      ^{{$}}
    108 CHECK: warning: class 'C' was previously declared as a struct
    109 CHECK: {{^}}class C;
    110 CHECK: {{^}}^{{$}}
    111 CHECK: note: previous use is here
    112 CHECK: {{^}}struct C;
    113 CHECK: {{^}}       ^{{$}}
    114 CHECK: warning: struct 'C' was previously declared as a class
    115 CHECK: {{^}}struct C;
    116 CHECK: {{^}}^{{$}}
    117 CHECK: note: previous use is here
    118 CHECK: {{^}}class C;
    119 CHECK: {{^}}      ^{{$}}
    120 CHECK: warning: 'C' defined as a class here but previously declared as a struct
    121 CHECK: {{^}}class C {};
    122 CHECK: {{^}}^{{$}}
    123 CHECK: note: did you mean class here?
    124 CHECK: {{^}}struct C;
    125 CHECK: {{^}}^~~~~~{{$}}
    126 CHECK: {{^}}class{{$}}
    127 CHECK: note: did you mean class here?
    128 CHECK: {{^}}struct C;
    129 CHECK: {{^}}^~~~~~{{$}}
    130 CHECK: {{^}}class{{$}}
    131 *** 'D' messages ***
    132 CHECK: error: redefinition of 'D'
    133 CHECK: {{^}}class D {};
    134 CHECK: {{^}}      ^{{$}}
    135 CHECK: note: previous definition is here
    136 CHECK: {{^}}struct D {};
    137 CHECK: {{^}}       ^{{$}}
    138 CHECK: warning: class 'D' was previously declared as a struct
    139 CHECK: {{^}}class D;
    140 CHECK: {{^}}^{{$}}
    141 CHECK: note: previous use is here
    142 CHECK: {{^}}struct D {};
    143 CHECK: {{^}}       ^{{$}}
    144 CHECK: note: did you mean struct here?
    145 CHECK: {{^}}class D;
    146 CHECK: {{^}}^~~~~{{$}}
    147 CHECK: {{^}}struct{{$}}
    148 *** 'E' messages ***
    149 *** 'F' messages ***
    150 *** 'G' messages ***
    151 CHECK: warning: struct template 'G' was previously declared as a class template
    152 CHECK: {{^}}template<class U> struct G;
    153 CHECK: {{^}}                  ^{{$}}
    154 CHECK: note: previous use is here
    155 CHECK: {{^}}template<class U> class G;
    156 CHECK: {{^}}                        ^{{$}}
    157 CHECK: warning: 'G' defined as a struct template here but previously declared as a class template
    158 CHECK: {{^}}template<class U> struct G {};
    159 CHECK: {{^}}                  ^{{$}}
    160 CHECK: note: did you mean struct here?
    161 CHECK: {{^}}template<class U> class G;
    162 CHECK: {{^}}                  ^~~~~
    163 CHECK: {{^}}                  struct
    164 */
    165