[cfe-commits] r101419 - in /cfe/trunk: lib/Parse/ParseDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaTemplate.cpp test/CXX/temp/temp.param/p3.cpp test/SemaCXX/exceptions.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 15 16:40:53 PDT 2010


Author: dgregor
Date: Thu Apr 15 18:40:53 2010
New Revision: 101419

URL: http://llvm.org/viewvc/llvm-project?rev=101419&view=rev
Log:
Audit uses of Sema::LookupSingleName for those lookups that are
intended for redeclarations, fixing those that need it. Fixes PR6831.

This uncovered an issue where the C++ type-specifier-seq parsing logic
would try to perform name lookup on an identifier after it already had
a type-specifier, which could also lead to spurious ambiguity errors
(as in PR6831, but with a different test case).


Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/CXX/temp/temp.param/p3.cpp
    cfe/trunk/test/SemaCXX/exceptions.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=101419&r1=101418&r2=101419&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Apr 15 18:40:53 2010
@@ -1437,6 +1437,11 @@
 
   switch (Tok.getKind()) {
   case tok::identifier:   // foo::bar
+    // If we already have a type specifier, this identifier is not a type.
+    if (DS.getTypeSpecType() != DeclSpec::TST_unspecified ||
+        DS.getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
+        DS.getTypeSpecSign() != DeclSpec::TSS_unspecified)
+      return false;
     // Check for need to substitute AltiVec keyword tokens.
     if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid))
       break;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=101419&r1=101418&r2=101419&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Apr 15 18:40:53 2010
@@ -4937,7 +4937,8 @@
   bool Invalid = D.isInvalidType();
   IdentifierInfo *II = D.getIdentifier();
   if (NamedDecl *PrevDecl = LookupSingleName(S, II, D.getIdentifierLoc(),
-                                             LookupOrdinaryName)) {
+                                             LookupOrdinaryName,
+                                             ForRedeclaration)) {
     // The scope should be freshly made just for us. There is just no way
     // it contains any previous declaration.
     assert(!S->isDeclScope(DeclPtrTy::make(PrevDecl)));

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=101419&r1=101418&r2=101419&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Apr 15 18:40:53 2010
@@ -67,13 +67,7 @@
 
   // Check for another declaration kind with the same name.
   NamedDecl *PrevDecl = LookupSingleName(TUScope, ClassName, ClassLoc,
-                                         LookupOrdinaryName);
-  if (PrevDecl && PrevDecl->isTemplateParameter()) {
-    // Maybe we will complain about the shadowed template parameter.
-    DiagnoseTemplateParameterShadow(ClassLoc, PrevDecl);
-    // Just pretend that we didn't see the previous declaration.
-    PrevDecl = 0;
-  }
+                                         LookupOrdinaryName, ForRedeclaration);
 
   if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
     Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
@@ -202,7 +196,7 @@
                                              SourceLocation ClassLocation) {
   // Look for previous declaration of alias name
   NamedDecl *ADecl = LookupSingleName(TUScope, AliasName, AliasLocation,
-                                      LookupOrdinaryName);
+                                      LookupOrdinaryName, ForRedeclaration);
   if (ADecl) {
     if (isa<ObjCCompatibleAliasDecl>(ADecl))
       Diag(AliasLocation, diag::warn_previous_alias_decl);
@@ -213,14 +207,14 @@
   }
   // Check for class declaration
   NamedDecl *CDeclU = LookupSingleName(TUScope, ClassName, ClassLocation,
-                                       LookupOrdinaryName);
+                                       LookupOrdinaryName, ForRedeclaration);
   if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(CDeclU)) {
     QualType T = TDecl->getUnderlyingType();
     if (T->isObjCInterfaceType()) {
       if (NamedDecl *IDecl = T->getAs<ObjCInterfaceType>()->getDecl()) {
         ClassName = IDecl->getIdentifier();
         CDeclU = LookupSingleName(TUScope, ClassName, ClassLocation,
-                                  LookupOrdinaryName);
+                                  LookupOrdinaryName, ForRedeclaration);
       }
     }
   }
@@ -547,7 +541,8 @@
   ObjCInterfaceDecl* IDecl = 0;
   // Check for another declaration kind with the same name.
   NamedDecl *PrevDecl
-    = LookupSingleName(TUScope, ClassName, ClassLoc, LookupOrdinaryName);
+    = LookupSingleName(TUScope, ClassName, ClassLoc, LookupOrdinaryName,
+                       ForRedeclaration);
   if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
     Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
     Diag(PrevDecl->getLocation(), diag::note_previous_definition);
@@ -1013,7 +1008,7 @@
     // Check for another declaration kind with the same name.
     NamedDecl *PrevDecl
       = LookupSingleName(TUScope, IdentList[i], IdentLocs[i], 
-                         LookupOrdinaryName);
+                         LookupOrdinaryName, ForRedeclaration);
     if (PrevDecl && PrevDecl->isTemplateParameter()) {
       // Maybe we will complain about the shadowed template parameter.
       DiagnoseTemplateParameterShadow(AtClassLoc, PrevDecl);

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=101419&r1=101418&r2=101419&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Apr 15 18:40:53 2010
@@ -456,7 +456,8 @@
 
   if (ParamName) {
     NamedDecl *PrevDecl = LookupSingleName(S, ParamName, ParamNameLoc,
-                                           LookupTagName);
+                                           LookupOrdinaryName,
+                                           ForRedeclaration);
     if (PrevDecl && PrevDecl->isTemplateParameter())
       Invalid = Invalid || DiagnoseTemplateParameterShadow(ParamNameLoc,
                                                            PrevDecl);
@@ -578,7 +579,8 @@
   IdentifierInfo *ParamName = D.getIdentifier();
   if (ParamName) {
     NamedDecl *PrevDecl = LookupSingleName(S, ParamName, D.getIdentifierLoc(),
-                                           LookupTagName);
+                                           LookupOrdinaryName,
+                                           ForRedeclaration);
     if (PrevDecl && PrevDecl->isTemplateParameter())
       Invalid = Invalid || DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
                                                            PrevDecl);

Modified: cfe/trunk/test/CXX/temp/temp.param/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.param/p3.cpp?rev=101419&r1=101418&r2=101419&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.param/p3.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.param/p3.cpp Thu Apr 15 18:40:53 2010
@@ -26,3 +26,15 @@
     // expected-error{{no viable conversion}}
   } 
 };
+
+namespace PR6831 {
+  namespace NA { struct S; }
+  namespace NB { struct S; }
+
+  using namespace NA;
+  using namespace NB;
+
+  template <typename S> void foo();
+  template <int S> void bar();
+  template <template<typename> class S> void baz();
+}

Modified: cfe/trunk/test/SemaCXX/exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exceptions.cpp?rev=101419&r1=101418&r2=101419&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/exceptions.cpp (original)
+++ cfe/trunk/test/SemaCXX/exceptions.cpp Thu Apr 15 18:40:53 2010
@@ -107,3 +107,16 @@
   }
   virtual void test () = 0; // expected-note{{pure virtual function 'test'}}
 };
+
+namespace PR6831 {
+  namespace NA { struct S; }
+  namespace NB { struct S; }
+  
+  void f() {
+    using namespace NA;
+    using namespace NB;
+    try {
+    } catch (int S) { 
+    }
+  }
+}





More information about the cfe-commits mailing list