[cfe-commits] r71895 - in /cfe/trunk: lib/AST/DeclarationName.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-function-1.cpp test/SemaTemplate/instantiate-function-2.cpp

Douglas Gregor dgregor at apple.com
Fri May 15 14:18:27 PDT 2009


Author: dgregor
Date: Fri May 15 16:18:27 2009
New Revision: 71895

URL: http://llvm.org/viewvc/llvm-project?rev=71895&view=rev
Log:
Make sure that we use the canonical type for the names of instantiated
constructors and destructors. This is a requirement of
DeclarationNameTable::getCXXSpecialName that we weren't assert()'ing,
so it should have been caught much earlier :(

Big thanks to Anders for the test case.


Added:
    cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp
Modified:
    cfe/trunk/lib/AST/DeclarationName.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp

Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=71895&r1=71894&r2=71895&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Fri May 15 16:18:27 2009
@@ -302,7 +302,8 @@
   assert(Kind >= DeclarationName::CXXConstructorName &&
          Kind <= DeclarationName::CXXConversionFunctionName &&
          "Kind must be a C++ special name kind");
-  
+  assert(Ty->isCanonical() && 
+         "Can only build C++ special names from canonical types");
   llvm::FoldingSet<CXXSpecialName> *SpecialNames 
     = static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=71895&r1=71894&r2=71895&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri May 15 16:18:27 2009
@@ -333,7 +333,8 @@
   CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
   QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
   DeclarationName Name
-    = SemaRef.Context.DeclarationNames.getCXXConstructorName(ClassTy);
+    = SemaRef.Context.DeclarationNames.getCXXConstructorName(
+                                 SemaRef.Context.getCanonicalType(ClassTy));
   CXXConstructorDecl *Constructor
     = CXXConstructorDecl::Create(SemaRef.Context, Record, D->getLocation(), 
                                  Name, T, D->isExplicit(), D->isInline(), 
@@ -362,6 +363,7 @@
   SemaRef.CheckFunctionDeclaration(Constructor, PrevDecl, Redeclaration,
                                    /*FIXME:*/OverloadableAttrRequired);
 
+  Record->addedConstructor(SemaRef.Context, Constructor);
   Owner->addDecl(SemaRef.Context, Constructor);
   return Constructor;
 }
@@ -377,7 +379,8 @@
 
   // Build the instantiated destructor declaration.
   CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
-  QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
+  QualType ClassTy = 
+    SemaRef.Context.getCanonicalType(SemaRef.Context.getTypeDeclType(Record));
   CXXDestructorDecl *Destructor
     = CXXDestructorDecl::Create(SemaRef.Context, Record,
                                 D->getLocation(),

Modified: cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp?rev=71895&r1=71894&r2=71895&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp Fri May 15 16:18:27 2009
@@ -64,8 +64,12 @@
     // IfStmt
     if (t > 0)
       return u;
-    else
-      return v; // expected-error{{incompatible type}}
+    else { 
+      if (t < 0)
+        return v; // expected-error{{incompatible type}}
+    }
+
+    return v;
   }
 };
 

Added: cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp?rev=71895&view=auto

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp Fri May 15 16:18:27 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template <typename T> struct S {
+  S() { }
+  S(T t);
+};
+
+template struct S<int>;
+
+void f() {
+  S<int> s1;
+  S<int> s2(10);
+}





More information about the cfe-commits mailing list