Weak references and variables that are not definitions are not required for early codegen/deserialization.
llvm-svn: 109796
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index af19e89..633538f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5550,6 +5550,10 @@
} else if (!isa<FunctionDecl>(D))
return false;
+ // Weak references don't produce any output by themselves.
+ if (D->hasAttr<WeakRefAttr>())
+ return false;
+
// Aliases and used decls are required.
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
return true;
@@ -5587,6 +5591,9 @@
const VarDecl *VD = cast<VarDecl>(D);
assert(VD->isFileVarDecl() && "Expected file scoped var");
+ if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly)
+ return false;
+
// Structs that have non-trivial constructors or destructors are required.
// FIXME: Handle references.
diff --git a/clang/test/PCH/cxx-templates.h b/clang/test/PCH/cxx-templates.h
index 47fa11e..9293219 100644
--- a/clang/test/PCH/cxx-templates.h
+++ b/clang/test/PCH/cxx-templates.h
@@ -109,3 +109,10 @@
template<typename> class C_PR7670;
template<> class C_PR7670<int>;
template<> class C_PR7670<int>;
+
+template <bool B>
+struct S2 {
+ static bool V;
+};
+
+extern template class S2<true>;