This patch fixes PR8755, a bug where we give a worse diagnostic when
templates are involved than when they aren't. In the case of "class
T<A>::iterator" we look up tag types only then error out when one isn't
found. The patch works by extended the error path to do a second lookup and
report a more informative error when a non-tag type is found.
Please review!
Nick
Index: test/SemaCXX/PR8755.cpp
===================================================================
--- test/SemaCXX/PR8755.cpp (revision 0)
+++ test/SemaCXX/PR8755.cpp (revision 0)
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <typename T>
+struct A {
+ typedef int iterator; // expected-note{{declared here}}
+};
+
+template <typename T>
+void f() {
+ class A <T> ::iterator foo; // expected-error{{elaborated type refers to a typedef}}
+}
+
+void g() {
+ f<int>(); // expected-note{{in instantiation of function template}}
+}
+
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h (revision 124082)
+++ lib/Sema/TreeTransform.h (working copy)
@@ -796,9 +796,28 @@
}
if (!Tag) {
- // FIXME: Would be nice to highlight just the source range.
- SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
- << Kind << Id << DC;
+ // Check where the name exists but isn't a tag type and use that to emit
+ // better diagnostics.
+ LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
+ SemaRef.LookupQualifiedName(Result, DC);
+ switch (Result.getResultKind()) {
+ case LookupResult::Found:
+ case LookupResult::FoundOverloaded:
+ case LookupResult::FoundUnresolvedValue: {
+ NamedDecl *SomeDecl = Result.getRepresentativeDecl();
+ unsigned Kind = 0;
+ if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
+ else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
+ SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
+ SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
+ break;
+ }
+ default:
+ // FIXME: Would be nice to highlight just the source range.
+ SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
+ << Kind << Id << DC;
+ break;
+ }
return QualType();
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits