aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/AST/ASTContext.cpp10
-rw-r--r--test/PCH/cxx-templates.cpp2
-rw-r--r--test/PCH/cxx-templates.h10
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 6ac18a8d88..7245c03160 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -7673,7 +7673,15 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
if (!VD->isFileVarDecl())
return false;
- } else if (!isa<FunctionDecl>(D))
+ } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ // We never need to emit an uninstantiated function template.
+ if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
+ return false;
+ } else
+ return false;
+
+ // If this is a member of a class template, we do not need to emit it.
+ if (D->getDeclContext()->isDependentContext())
return false;
// Weak references don't produce any output by themselves.
diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp
index ddebae4df2..58c4c177fd 100644
--- a/test/PCH/cxx-templates.cpp
+++ b/test/PCH/cxx-templates.cpp
@@ -5,7 +5,7 @@
// Test with pch.
// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h
// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o -
-// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s
// expected-no-diagnostics
diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h
index 00631ddbfb..e672b0b387 100644
--- a/test/PCH/cxx-templates.h
+++ b/test/PCH/cxx-templates.h
@@ -259,3 +259,13 @@ void f() {
template void f<int>();
}
+
+template<typename T> void doNotDeserialize() {}
+template<typename T> struct ContainsDoNotDeserialize {
+ static int doNotDeserialize;
+};
+template<typename T> struct ContainsDoNotDeserialize2 {
+ static void doNotDeserialize();
+};
+template<typename T> int ContainsDoNotDeserialize<T>::doNotDeserialize = 0;
+template<typename T> void ContainsDoNotDeserialize2<T>::doNotDeserialize() {}