[cfe-commits] r131920 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CodeGenCXX/pr9965.cpp

Sean Hunt scshunt at csclub.uwaterloo.ca
Mon May 23 14:07:59 PDT 2011


Author: coppro
Date: Mon May 23 16:07:59 2011
New Revision: 131920

URL: http://llvm.org/viewvc/llvm-project?rev=131920&view=rev
Log:
Correctly propagate defaultedness across template instantiation. This
fixes PR9965, but we're not out of the water yet, as we do not
successfully handle out-of-line definitions, due to my utter
misunderstanding of how we manage templates.

Added:
    cfe/trunk/test/CodeGenCXX/pr9965.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=131920&r1=131919&r2=131920&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon May 23 16:07:59 2011
@@ -2997,7 +2997,8 @@
   //   have inherited constructors.
   DeclareInheritedConstructors(Record);
 
-  CheckExplicitlyDefaultedMethods(Record);
+  if (!Record->isDependentType())
+    CheckExplicitlyDefaultedMethods(Record);
 }
 
 void Sema::CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record) {
@@ -8657,6 +8658,12 @@
   CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Dcl);
 
   if (MD) {
+    if (MD->getParent()->isDependentType()) {
+      MD->setDefaulted();
+      MD->setExplicitlyDefaulted();
+      return;
+    }
+
     CXXSpecialMember Member = getSpecialMember(MD);
     if (Member == CXXInvalid) {
       Diag(DefaultLoc, diag::err_default_special_members);

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=131920&r1=131919&r2=131920&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon May 23 16:07:59 2011
@@ -1264,6 +1264,7 @@
       PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
     PrincipalDecl->setNonMemberOperator();
 
+  assert(!D->isDefaulted() && "only methods should be defaulted");
   return Function;
 }
 
@@ -1496,7 +1497,14 @@
     else
       Owner->addDecl(DeclToAdd);
   }
-  
+
+  if (D->isExplicitlyDefaulted()) {
+    SemaRef.SetDeclDefaulted(Method, Method->getLocation());
+  } else {
+    assert(!D->isDefaulted() &&
+           "should not implicitly default uninstantiated function");
+  }
+
   return Method;
 }
 

Added: cfe/trunk/test/CodeGenCXX/pr9965.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr9965.cpp?rev=131920&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pr9965.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/pr9965.cpp Mon May 23 16:07:59 2011
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++0x -emit-llvm -o - %s | FileCheck %s
+template<typename T>
+struct X
+{
+    X() = default;
+};
+
+X<int> x;
+// CHECK: define internal void @__cxx_global_var_init()
+// CHECK: call void @_ZN1XIiEC1Ev
+// CHECK: define linkonce_odr void @_ZN1XIiEC1Ev
+// CHECK: define linkonce_odr void @_ZN1XIiEC2Ev





More information about the cfe-commits mailing list