]> granicus.if.org Git - clang/commitdiff
Make sure that CodeGen sees template instantiations.
authorDouglas Gregor <dgregor@apple.com>
Tue, 26 May 2009 20:50:29 +0000 (20:50 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 26 May 2009 20:50:29 +0000 (20:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72433 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CodeGenCXX/explicit-instantiation.cpp [new file with mode: 0644]

index a5b09117885af9af560e7d8af5f5d863fce4b220..3c32a21073d3607158aed17d4a32f373530994d2 100644 (file)
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===/
 
 #include "Sema.h"
+#include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/DeclTemplate.h"
@@ -779,6 +780,9 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
   // Exit the scope of this instantiation.
   CurContext = PreviousContext;
 
+  if (!Invalid)
+    Consumer.HandleTagDeclDefinition(Instantiation);
+
   // If this is an explicit instantiation, instantiate our members, too.
   if (!Invalid && ExplicitInstantiation) {
     Inst.Clear();
index b9a9ae8c50ac6395a3c697b18c1bef9fca448051..90c86ec57e63fb909e7aa1cb9234f0929d50239e 100644 (file)
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===/
 #include "Sema.h"
+#include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclVisitor.h"
@@ -622,6 +623,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
                           /*IsInstantiation=*/true);
 
   CurContext = PreviousContext;
+
+  DeclGroupRef DG(Function);
+  Consumer.HandleTopLevelDecl(DG);
 }
 
 /// \brief Instantiate the definition of the given variable from its
diff --git a/test/CodeGenCXX/explicit-instantiation.cpp b/test/CodeGenCXX/explicit-instantiation.cpp
new file mode 100644 (file)
index 0000000..38966aa
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: clang-cc -emit-llvm -femit-all-decls -o %t %s &&
+// RUN: grep "_ZNK4plusIillEclERKiRKl" %t | count 1
+
+template<typename T, typename U, typename Result>
+struct plus {
+  Result operator()(const T& t, const U& u) const {
+    return t + u;
+  }
+};
+
+template struct plus<int, long, long>;