Improve diagnostics when an elaborated-type-specifer containing a
nested-name-specifier (e.g., "class T::foo") fails to find a tag
member in the scope nominated by the
nested-name-specifier. Previously, we gave a bland
error: 'Nested' does not name a tag member in the specified scope
which didn't actually say where we were looking, which was rather
horrible when the nested-name-specifier was instantiated. Now, we give
something a bit better:
error: no class named 'Nested' in 'NoDepBase<T>'
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100060 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 2439164..4e177fb 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2182,7 +2182,7 @@
def err_invalid_declarator_in_function : Error<
"definition or redeclaration of %0 not allowed inside a function">;
def err_not_tag_in_scope : Error<
- "%0 does not name a tag member in the specified scope">;
+ "no %select{struct|union|class|enum}0 named %1 in %2">;
def err_cannot_form_pointer_to_member_of_reference_type : Error<
"cannot form a pointer-to-member to member %0 of reference type %1">;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index eef73d8..f3d0dcf 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -4786,7 +4786,8 @@
}
// A tag 'foo::bar' must already exist.
- Diag(NameLoc, diag::err_not_tag_in_scope) << Name << SS.getRange();
+ Diag(NameLoc, diag::err_not_tag_in_scope)
+ << Kind << Name << DC << SS.getRange();
Name = 0;
Invalid = true;
goto CreateNewDecl;
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 9777569..3375ccc 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -693,7 +693,8 @@
if (!PrevClassTemplate && Qualifier) {
SemaRef.Diag(Pattern->getLocation(), diag::err_not_tag_in_scope)
- << Pattern->getDeclName() << Pattern->getQualifierRange();
+ << D->getTemplatedDecl()->getTagKind() << Pattern->getDeclName() << DC
+ << Pattern->getQualifierRange();
return 0;
}
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index b08447e..f9ffd3f 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -618,9 +618,9 @@
}
if (!Tag) {
- // FIXME: Crummy diagnostic
+ // FIXME: Would be nice to highlight just the source range.
SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
- << Id << SR;
+ << Kind << Id << DC;
return QualType();
}
diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
index bfb4780..c530311 100644
--- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
+++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
@@ -40,10 +40,10 @@
void c3(union B<float>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}}
void c4(enum B<float>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}}
-void d1(struct B<int>::Member); // expected-error {{'Member' does not name a tag member in the specified scope}}
-void d2(class B<int>::Member); // expected-error {{'Member' does not name a tag member in the specified scope}}
-void d3(union B<int>::Member); // expected-error {{'Member' does not name a tag member in the specified scope}}
-void d4(enum B<int>::Member); // expected-error {{'Member' does not name a tag member in the specified scope}}
+void d1(struct B<int>::Member); // expected-error {{no struct named 'Member' in 'B<int>'}}
+void d2(class B<int>::Member); // expected-error {{no class named 'Member' in 'B<int>'}}
+void d3(union B<int>::Member); // expected-error {{no union named 'Member' in 'B<int>'}}
+void d4(enum B<int>::Member); // expected-error {{no enum named 'Member' in 'B<int>'}}
void e1(struct B<A>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}}
void e2(class B<A>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}}
@@ -51,7 +51,7 @@
void e4(enum B<A>::Member); // expected-error {{use of 'Member' with tag type that does not match previous declaration}}
template <class T> struct C {
- void foo(class B<T>::Member); // expected-error{{'Member' does not name a tag member in the specified scope}} \
+ void foo(class B<T>::Member); // expected-error{{no class named 'Member' in 'B<int>'}} \
// expected-error{{use of 'Member' with tag type that does not match previous declaration}}
};
diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp
index 8657c0d..9a611c3 100644
--- a/test/SemaCXX/nested-name-spec.cpp
+++ b/test/SemaCXX/nested-name-spec.cpp
@@ -64,7 +64,7 @@
A::C c1;
struct A::C c2;
struct S : public A::C {};
-struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
+struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}}
namespace A2 {
typedef int INT;
diff --git a/test/SemaTemplate/dependent-base-classes.cpp b/test/SemaTemplate/dependent-base-classes.cpp
index 600115b..d0dd9c9 100644
--- a/test/SemaTemplate/dependent-base-classes.cpp
+++ b/test/SemaTemplate/dependent-base-classes.cpp
@@ -55,7 +55,7 @@
template<typename T>
struct NoDepBase {
int foo() {
- class NoDepBase::Nested nested; // expected-error{{'Nested' does not name a tag member in the specified scope}}
+ class NoDepBase::Nested nested; // expected-error{{no class named 'Nested' in 'NoDepBase<T>'}}
typedef typename NoDepBase::template MemberTemplate<T>::type type; // expected-error{{'MemberTemplate' following the 'template' keyword does not refer to a template}} \
// FIXME: expected-error{{unqualified-id}}
return NoDepBase::a; // expected-error{{no member named 'a' in 'NoDepBase<T>'}}
diff --git a/test/SemaTemplate/instantiate-declref.cpp b/test/SemaTemplate/instantiate-declref.cpp
index f883b93..2d27075 100644
--- a/test/SemaTemplate/instantiate-declref.cpp
+++ b/test/SemaTemplate/instantiate-declref.cpp
@@ -36,7 +36,7 @@
typedef int INT;
template struct N::Outer::Inner::InnerTemplate<INT>::VeryInner;
-template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{'UeberInner' does not name a tag member}}
+template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{no struct named 'UeberInner' in 'N::Outer::Inner::InnerTemplate<int>'}}
namespace N2 {
struct Outer2 {