Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -4553,7 +4553,9 @@ "%select{typedef|type alias|type alias template}0 " "redefinition with different types%diff{ ($ vs $)|}1,2">; def err_tag_reference_non_tag : Error< - "elaborated type refers to %select{a non-tag type|a typedef|a type alias|a template|a type alias template|a template template argument}0">; + "%0 is a %select{non-tag type|typedef|type alias|template|type alias " + "template|template template argument}1 that cannot be referenced with a " + "%select{struct|interface|union|class|enum}2 tag">; def err_tag_reference_conflict : Error< "implicit declaration introduced by elaborated type conflicts with " "%select{a declaration|a typedef|a type alias|a template}0 of the same name">; Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -13205,7 +13205,7 @@ if ((TUK == TUK_Reference || TUK == TUK_Friend) && !Previous.isForRedeclaration()) { NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl); - Diag(NameLoc, diag::err_tag_reference_non_tag) << NTK; + Diag(NameLoc, diag::err_tag_reference_non_tag) << PrevDecl << NTK << Kind; Diag(PrevDecl->getLocation(), diag::note_declared_at); Invalid = true; Index: lib/Sema/SemaTemplate.cpp =================================================================== --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -2489,7 +2489,8 @@ // If the identifier resolves to a typedef-name or the simple-template-id // resolves to an alias template specialization, the // elaborated-type-specifier is ill-formed. - Diag(TemplateLoc, diag::err_tag_reference_non_tag) << NTK_TypeAliasTemplate; + Diag(TemplateLoc, diag::err_tag_reference_non_tag) + << TAT << NTK_TypeAliasTemplate << TagKind; Diag(TAT->getLocation(), diag::note_declared_at); } @@ -7462,7 +7463,7 @@ if (!ClassTemplate) { NonTagKind NTK = getNonTagTypeDeclKind(TD); - Diag(TemplateNameLoc, diag::err_tag_reference_non_tag) << NTK; + Diag(TemplateNameLoc, diag::err_tag_reference_non_tag) << TD << NTK << Kind; Diag(TD->getLocation(), diag::note_previous_use); return true; } Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -1014,7 +1014,8 @@ case LookupResult::FoundUnresolvedValue: { NamedDecl *SomeDecl = Result.getRepresentativeDecl(); Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl); - SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << NTK; + SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl + << NTK << Kind; SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); break; } @@ -5706,7 +5707,8 @@ Template.getAsTemplateDecl())) { SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), diag::err_tag_reference_non_tag) - << Sema::NTK_TypeAliasTemplate; + << TAT << Sema::NTK_TypeAliasTemplate + << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); } } Index: test/CXX/basic/basic.lookup/basic.lookup.elab/p2.cpp =================================================================== --- test/CXX/basic/basic.lookup/basic.lookup.elab/p2.cpp +++ test/CXX/basic/basic.lookup/basic.lookup.elab/p2.cpp @@ -9,7 +9,7 @@ typedef int A; // expected-note {{declared here}} int test() { - struct A a; // expected-error {{elaborated type refers to a typedef}} + struct A a; // expected-error {{'A' is a typedef that cannot be referenced with a struct tag}} return a.foo; } } @@ -18,7 +18,7 @@ template class A; // expected-note {{declared here}} int test() { - struct A a; // expected-error {{elaborated type refers to a template}} + struct A a; // expected-error {{'A' is a template that cannot be referenced with a struct tag}} return a.foo; } } Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp =================================================================== --- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp +++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp @@ -2,18 +2,18 @@ struct A { typedef int type; }; template using X = A; // expected-note {{declared here}} -struct X* p2; // expected-error {{elaborated type refers to a type alias template}} +struct X* p2; // expected-error {{'X' is a type alias template that cannot be referenced with a struct tag}} template using Id = T; // expected-note {{declared here}} template class F> struct Y { - struct F i; // expected-error {{elaborated type refers to a type alias template}} + struct F i; // expected-error {{'Id' is a type alias template that cannot be referenced with a struct tag}} typename F::type j; // ok // FIXME: don't produce the diagnostic both for the definition and the instantiation. template using U = F; // expected-note 2{{declared here}} - struct Y::template U k; // expected-error 2{{elaborated type refers to a type alias template}} + struct Y::template U k; // expected-error 2{{'U' is a type alias template that cannot be referenced with a struct tag}} typename Y::template U l; // ok }; template struct Y; // expected-note {{requested here}} Index: test/CXX/drs/dr2xx.cpp =================================================================== --- test/CXX/drs/dr2xx.cpp +++ test/CXX/drs/dr2xx.cpp @@ -620,7 +620,7 @@ template struct A { typedef typename T::type type; // ok even if this is a typedef-name, because // it's not an elaborated-type-specifier - typedef struct T::type foo; // expected-error {{elaborated type refers to a typedef}} + typedef struct T::type foo; // expected-error {{'type' is a typedef that cannot be referenced with a struct tag}} }; struct B { struct type {}; }; struct C { typedef struct {} type; }; // expected-note {{here}} @@ -1037,8 +1037,8 @@ C::type i3; struct A a; - struct B b; // expected-error {{refers to a typedef}} - struct C c; // expected-error {{refers to a typedef}} + struct B b; // expected-error {{'B' is a typedef}} + struct C c; // expected-error {{'C' is a typedef}} B::B() {} // expected-error {{requires a type specifier}} B::A() {} // ok Index: test/CXX/drs/dr4xx.cpp =================================================================== --- test/CXX/drs/dr4xx.cpp +++ test/CXX/drs/dr4xx.cpp @@ -90,7 +90,7 @@ struct S *p; { typedef struct S S; // expected-note {{here}} - struct S *p; // expected-error {{refers to a typedef}} + struct S *p; // expected-error {{'S' is a typedef}} } } struct S {}; Index: test/CXX/temp/temp.decls/temp.friend/p1.cpp =================================================================== --- test/CXX/temp/temp.decls/temp.friend/p1.cpp +++ test/CXX/temp/temp.decls/temp.friend/p1.cpp @@ -174,7 +174,7 @@ // This shouldn't crash. template class D { - friend class A; // expected-error {{elaborated type refers to a template}} + friend class A; // expected-error {{'A' is a template that cannot be referenced with a class tag}} }; template class D; } Index: test/CXX/temp/temp.spec/no-body.cpp =================================================================== --- test/CXX/temp/temp.spec/no-body.cpp +++ test/CXX/temp/temp.spec/no-body.cpp @@ -43,7 +43,7 @@ namespace unsupported { #ifndef FIXING - template struct y; // expected-error {{elaborated type refers to a template}} + template struct y; // expected-error {{'y' is a template that cannot be referenced with a struct tag}} #endif } Index: test/SemaCXX/PR8755.cpp =================================================================== --- test/SemaCXX/PR8755.cpp +++ test/SemaCXX/PR8755.cpp @@ -7,7 +7,7 @@ template void f() { - class A ::iterator foo; // expected-error{{elaborated type refers to a typedef}} + class A ::iterator foo; // expected-error{{'iterator' is a typedef that cannot be referenced with a class tag}} } void g() { Index: test/SemaCXX/using-decl-templates.cpp =================================================================== --- test/SemaCXX/using-decl-templates.cpp +++ test/SemaCXX/using-decl-templates.cpp @@ -90,7 +90,7 @@ template struct A { }; template using APtr = A; // expected-note{{previous use is here}} - template struct APtr; // expected-error{{elaborated type refers to a type alias template}} + template struct APtr; // expected-error{{'APtr' is a type alias template that cannot be referenced with a struct tag}} } namespace DontDiagnoseInvalidTest { Index: test/SemaTemplate/template-id-expr.cpp =================================================================== --- test/SemaTemplate/template-id-expr.cpp +++ test/SemaTemplate/template-id-expr.cpp @@ -100,5 +100,5 @@ class C {}; template