C++11 half of r147023: In C++11, additionally eagerly instantiate:
- constexpr function template instantiations
- variables of reference type
- constexpr variables
llvm-svn: 147031
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ebcdcf5..9ae39f1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6544,8 +6544,7 @@
for (unsigned I = 0, N = Notes.size(); I != N; ++I)
Diag(Notes[I].first, Notes[I].second);
}
- } else if (getLangOptions().CPlusPlus && !Type.isVolatileQualified() &&
- Type.isConstQualified() && Type->isIntegralOrEnumerationType()) {
+ } else if (var->isUsableInConstantExpressions()) {
// Check whether the initializer of a const variable of integral or
// enumeration type is an ICE now, since we can't tell whether it was
// initialized by a constant expression if we check later.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3a61fe5..9d2298a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9491,6 +9491,11 @@
cast<CXXRecordDecl>(Function->getDeclContext())->isLocalClass())
PendingLocalImplicitInstantiations.push_back(std::make_pair(Function,
Loc));
+ else if (Function->getTemplateInstantiationPattern()->isConstexpr())
+ // Do not defer instantiations of constexpr functions, to avoid the
+ // expression evaluator needing to call back into Sema if it sees a
+ // call to such a function.
+ InstantiateFunctionDefinition(Loc, Function);
else
PendingInstantiations.push_back(std::make_pair(Function, Loc));
}
@@ -9526,9 +9531,9 @@
// This is a modification of an existing AST node. Notify listeners.
if (ASTMutationListener *L = getASTMutationListener())
L->StaticDataMemberInstantiated(Var);
- QualType T = Var->getType();
- if (T.isConstQualified() && !T.isVolatileQualified() &&
- T->isIntegralOrEnumerationType())
+ if (Var->isUsableInConstantExpressions())
+ // Do not defer instantiations of variables which could be used in a
+ // constant expression.
InstantiateStaticDataMemberDefinition(Loc, Var);
else
PendingInstantiations.push_back(std::make_pair(Var, Loc));