From: David Majnemer Date: Fri, 27 Sep 2013 04:14:12 +0000 (+0000) Subject: Sema: Respect -fdelayed-template-parsing when parsing constexpr functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54679205de1a348f410d03ce4b331b56b21dce49;p=clang Sema: Respect -fdelayed-template-parsing when parsing constexpr functions Functions declared as constexpr must have their parsing delayed in -fdelayed-template-parsing mode so as not to upset later template instantiation. N.B. My reading of the standard makes it seem like delayed template parsing is at odds with constexpr. We may want to make refinements in other places in clang to make constexpr play nicer with this feature. This fixes PR17334. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191484 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 10ed15a290..a52ebf6e2f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11010,7 +11010,8 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func) { // However, they cannot be referenced if they are deleted, and they are // deleted whenever the implicit definition of the special member would // fail. - if (!Func->isConstexpr() || Func->getBody()) + if (!(Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing) || + Func->getBody()) return; CXXMethodDecl *MD = dyn_cast(Func); if (!Func->isImplicitlyInstantiable() && (!MD || MD->isUserProvided())) @@ -11101,13 +11102,14 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func) { } } - if (!AlreadyInstantiated || Func->isConstexpr()) { + if (!AlreadyInstantiated || + (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing)) { if (isa(Func->getDeclContext()) && cast(Func->getDeclContext())->isLocalClass() && ActiveTemplateInstantiations.size()) PendingLocalImplicitInstantiations.push_back( std::make_pair(Func, PointOfInstantiation)); - else if (Func->isConstexpr()) + else if (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing) // 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. diff --git a/test/Parser/DelayedTemplateParsing.cpp b/test/Parser/DelayedTemplateParsing.cpp index 3e429d4116..201fe1b466 100644 --- a/test/Parser/DelayedTemplateParsing.cpp +++ b/test/Parser/DelayedTemplateParsing.cpp @@ -102,3 +102,15 @@ namespace rdar11700604 { }; } +namespace PR17334 { + +template struct ArrayRef { + constexpr ArrayRef() {} +}; +template void CreateConstInBoundsGEP2_32() { + ArrayRef<> IdxList; +} +void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); } + +} +