]> granicus.if.org Git - clang/commitdiff
Don't try emitting dllexported explicitly defaulted non-trivial ctors twice during...
authorHans Wennborg <hans@hanshq.net>
Fri, 2 Aug 2019 07:51:41 +0000 (07:51 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 2 Aug 2019 07:51:41 +0000 (07:51 +0000)
Trying to emit the definition twice triggers an assert.

Differential revision: https://reviews.llvm.org/D65579

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367661 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/dllexport.cpp

index 5f90790d7ffbb82b7de211d40ba120fbfe1d3922..accca46666b359d65794c54d1eded95d5cbdc085 100644 (file)
@@ -11543,7 +11543,13 @@ void Sema::ActOnFinishCXXNonNestedClass(Decl *D) {
     std::swap(DelayedDllExportMemberFunctions, WorkList);
     for (CXXMethodDecl *M : WorkList) {
       DefineImplicitSpecialMember(*this, M, M->getLocation());
-      ActOnFinishInlineFunctionDef(M);
+
+      // Pass the method to the consumer to get emitted. This is not necessary
+      // for explicit instantiation definitions, as they will get emitted
+      // anyway.
+      if (M->getParent()->getTemplateSpecializationKind() !=
+          TSK_ExplicitInstantiationDefinition)
+        ActOnFinishInlineFunctionDef(M);
     }
   }
 }
index 5d4523f2ea61c74719badf5568bbb2c4f1756e90..59ba6d8548830a0862daa7d6e51ec8e3c0a5f1fc 100644 (file)
@@ -860,6 +860,13 @@ struct PR40006 {
 };
 // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::PR40006"* @"??0PR40006@InClassInits@@QAE@XZ"
 
+// PR42857: Clang would try to emit the non-trivial explicitly defaulted
+// dllexport ctor twice when doing an explicit instantiation definition.
+struct Qux { Qux(); };
+template <typename T> struct PR42857 { __declspec(dllexport) PR42857() = default; Qux q; };
+template struct PR42857<int>;
+// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::PR42857"* @"??0?$PR42857@H@InClassInits@@QAE@XZ"
+
 }
 
 // We had an issue where instantiating A would force emission of B's delayed