200 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s2// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s3class X; // expected-note 2{{here}}4typedef struct X * X_t; // expected-warning{{previously declared}}5union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}6 7template<typename T> struct Y; // expected-note{{did you mean class here?}}8template<class U> class Y { }; // expected-warning{{previously declared}}9 10template <typename>11struct Z {12 struct Z { // expected-error{{member 'Z' has the same name as its class}}13 };14};15 16class A;17class A; // expected-note{{previous use is here}}18struct A; // expected-warning{{struct 'A' was previously declared as a class}}19 20class B; // expected-note{{did you mean struct here?}}21class B; // expected-note{{previous use is here}}\22 // expected-note{{did you mean struct here?}}23struct B; // expected-warning{{struct 'B' was previously declared as a class}}24struct B {}; // expected-warning{{'B' defined as a struct here but previously declared as a class}}25 26class C; // expected-note{{previous use is here}}27struct C; // expected-warning{{struct 'C' was previously declared as a class}}\28 // expected-note{{previous use is here}}\29 // expected-note{{did you mean class here?}}30class C; // expected-warning{{class 'C' was previously declared as a struct}}\31 // expected-note{{previous use is here}}32struct C; // expected-warning{{struct 'C' was previously declared as a class}}\33 // expected-note{{did you mean class here?}}34class C {}; // expected-warning{{'C' defined as a class here but previously declared as a struct}}35 36struct D {}; // expected-note{{previous definition is here}}\37 // expected-note{{previous use is here}}38class D {}; // expected-error{{redefinition of 'D'}}39struct D;40class D; // expected-warning{{class 'D' was previously declared as a struct}}\41 // expected-note{{did you mean struct here?}}42 43class E;44class E;45class E {};46class E;47 48struct F;49struct F;50struct F {}; // expected-note {{previous use}}51struct F;52class F; // expected-warning {{previously declared as a struct}} expected-note {{did you mean struct}}53 54template<class U> class G; // expected-note{{previous use is here}}\55 // expected-note{{did you mean struct here?}}56template<class U> struct G; // expected-warning{{struct template 'G' was previously declared as a class template}}57template<class U> struct G {}; // expected-warning{{'G' defined as a struct template here but previously declared as a class template}}58 59// Declarations from contexts where the warning is disabled are entirely60// ignored for the purpose of this warning.61struct J;62struct K; // expected-note {{previous use}}63struct L;64struct M; // expected-note {{previous use}}65 66#pragma clang diagnostic push67#pragma clang diagnostic ignored "-Wmismatched-tags"68struct H;69class I {};70class J;71class K;72class L;73class M {};74#pragma clang diagnostic pop75 76class H; // expected-note {{previous use}}77struct H; // expected-warning {{previously declared as a class}}78 79struct I; // expected-note {{previous use}}80class I; // expected-warning {{previously declared as a struct}}81 82struct J;83class K; // expected-warning {{previously declared as a struct}}84struct L;85class M; // expected-warning {{previously declared as a struct}}86 87/*88*** 'X' messages ***89CHECK: warning: struct 'X' was previously declared as a class90CHECK: {{^}}typedef struct X * X_t;91CHECK: {{^}} ^{{$}}92CHECK: note: previous use is here93CHECK: {{^}}class X;94CHECK: {{^}} ^{{$}}95CHECK: error: use of 'X' with tag type that does not match previous declaration96CHECK: {{^}}union X { int x; float y; };97CHECK: {{^}}^~~~~{{$}}98CHECK: {{^}}class{{$}}99CHECK: note: previous use is here100CHECK: {{^}}class X;101CHECK: {{^}} ^{{$}}102*** 'Y' messages ***103CHECK: warning: 'Y' defined as a class template here but104 previously declared as a struct template105CHECK: {{^}}template<class U> class Y { };106CHECK: {{^}} ^{{$}}107CHECK: note: did you mean class here?108CHECK: {{^}}template<typename T> struct Y;109CHECK: {{^}} ^~~~~~{{$}}110CHECK: {{^}} class{{$}}111*** 'A' messages ***112CHECK: warning: struct 'A' was previously declared as a class113CHECK: {{^}}struct A;114CHECK: {{^}}^{{$}}115CHECK: note: previous use is here116CHECK: {{^}}class A;117CHECK: {{^}} ^{{$}}118*** 'B' messages ***119CHECK: warning: struct 'B' was previously declared as a class120CHECK: {{^}}struct B;121CHECK: {{^}}^{{$}}122CHECK: note: previous use is here123CHECK: {{^}}class B;124CHECK: {{^}} ^{{$}}125CHECK: 'B' defined as a struct here but previously declared as a class126CHECK: {{^}}struct B {};127CHECK: {{^}}^{{$}}128CHECK: note: did you mean struct here?129CHECK: {{^}}class B;130CHECK: {{^}}^~~~~{{$}}131CHECK: {{^}}struct{{$}}132CHECK: note: did you mean struct here?133CHECK: {{^}}class B;134CHECK: {{^}}^~~~~{{$}}135CHECK: {{^}}struct{{$}}136*** 'C' messages ***137CHECK: warning: struct 'C' was previously declared as a class138CHECK: {{^}}struct C;139CHECK: {{^}}^{{$}}140CHECK: note: previous use is here141CHECK: {{^}}class C;142CHECK: {{^}} ^{{$}}143CHECK: warning: class 'C' was previously declared as a struct144CHECK: {{^}}class C;145CHECK: {{^}}^{{$}}146CHECK: note: previous use is here147CHECK: {{^}}struct C;148CHECK: {{^}} ^{{$}}149CHECK: warning: struct 'C' was previously declared as a class150CHECK: {{^}}struct C;151CHECK: {{^}}^{{$}}152CHECK: note: previous use is here153CHECK: {{^}}class C;154CHECK: {{^}} ^{{$}}155CHECK: warning: 'C' defined as a class here but previously declared as a struct156CHECK: {{^}}class C {};157CHECK: {{^}}^{{$}}158CHECK: note: did you mean class here?159CHECK: {{^}}struct C;160CHECK: {{^}}^~~~~~{{$}}161CHECK: {{^}}class{{$}}162CHECK: note: did you mean class here?163CHECK: {{^}}struct C;164CHECK: {{^}}^~~~~~{{$}}165CHECK: {{^}}class{{$}}166*** 'D' messages ***167CHECK: error: redefinition of 'D'168CHECK: {{^}}class D {};169CHECK: {{^}} ^{{$}}170CHECK: note: previous definition is here171CHECK: {{^}}struct D {};172CHECK: {{^}} ^{{$}}173CHECK: warning: class 'D' was previously declared as a struct174CHECK: {{^}}class D;175CHECK: {{^}}^{{$}}176CHECK: note: previous use is here177CHECK: {{^}}struct D {};178CHECK: {{^}} ^{{$}}179CHECK: note: did you mean struct here?180CHECK: {{^}}class D;181CHECK: {{^}}^~~~~{{$}}182CHECK: {{^}}struct{{$}}183*** 'E' messages ***184*** 'F' messages ***185*** 'G' messages ***186CHECK: warning: struct template 'G' was previously declared as a class template187CHECK: {{^}}template<class U> struct G;188CHECK: {{^}} ^{{$}}189CHECK: note: previous use is here190CHECK: {{^}}template<class U> class G;191CHECK: {{^}} ^{{$}}192CHECK: warning: 'G' defined as a struct template here but previously declared as a class template193CHECK: {{^}}template<class U> struct G {};194CHECK: {{^}} ^{{$}}195CHECK: note: did you mean struct here?196CHECK: {{^}}template<class U> class G;197CHECK: {{^}} ^~~~~198CHECK: {{^}} struct199*/200