r193274 - Parse: Disable delayed template parsing for constexpr functions

David Majnemer david.majnemer at gmail.com
Wed Oct 23 14:31:20 PDT 2013


Author: majnemer
Date: Wed Oct 23 16:31:20 2013
New Revision: 193274

URL: http://llvm.org/viewvc/llvm-project?rev=193274&view=rev
Log:
Parse: Disable delayed template parsing for constexpr functions

Commit r191484 treated constexpr function templates as normal function
templates with respect to delaying their parsing.  However, this is
unnecessarily restrictive because there is no compatibility concern with
constexpr, MSVC doesn't support it.

Instead, simply disable delayed template parsing for constexpr function
templates.  This largely reverts the changes made in r191484 but keeps
it's unit test.

This fixes PR17661.

Modified:
    cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Parser/DelayedTemplateParsing.cpp

Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=193274&r1=193273&r2=193274&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Wed Oct 23 16:31:20 2013
@@ -115,6 +115,7 @@ NamedDecl *Parser::ParseCXXInlineMethodD
   // the tokens and store them for parsing at the end of the translation unit.
   if (getLangOpts().DelayedTemplateParsing &&
       DefinitionKind == FDK_Definition &&
+      !D.getDeclSpec().isConstexprSpecified() &&
       ((Actions.CurContext->isDependentContext() ||
         (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
          TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) &&

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=193274&r1=193273&r2=193274&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Oct 23 16:31:20 2013
@@ -990,9 +990,9 @@ Decl *Parser::ParseFunctionDefinition(Pa
 
   // In delayed template parsing mode, for function template we consume the
   // tokens and store them for late parsing at the end of the translation unit.
-  if (getLangOpts().DelayedTemplateParsing &&
-      Tok.isNot(tok::equal) &&
-      TemplateInfo.Kind == ParsedTemplateInfo::Template) {
+  if (getLangOpts().DelayedTemplateParsing && Tok.isNot(tok::equal) &&
+      TemplateInfo.Kind == ParsedTemplateInfo::Template &&
+      !D.getDeclSpec().isConstexprSpecified()) {
     MultiTemplateParamsArg TemplateParameterLists(*TemplateInfo.TemplateParams);
     
     ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=193274&r1=193273&r2=193274&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Oct 23 16:31:20 2013
@@ -11088,8 +11088,7 @@ void Sema::MarkFunctionReferenced(Source
     // 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() && !getLangOpts().DelayedTemplateParsing) ||
-        Func->getBody())
+    if (!Func->isConstexpr() || Func->getBody())
       return;
     CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Func);
     if (!Func->isImplicitlyInstantiable() && (!MD || MD->isUserProvided()))
@@ -11180,14 +11179,13 @@ void Sema::MarkFunctionReferenced(Source
       }
     }
 
-    if (!AlreadyInstantiated ||
-        (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing)) {
+    if (!AlreadyInstantiated || Func->isConstexpr()) {
       if (isa<CXXRecordDecl>(Func->getDeclContext()) &&
           cast<CXXRecordDecl>(Func->getDeclContext())->isLocalClass() &&
           ActiveTemplateInstantiations.size())
         PendingLocalImplicitInstantiations.push_back(
             std::make_pair(Func, PointOfInstantiation));
-      else if (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing)
+      else if (Func->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.

Modified: cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/DelayedTemplateParsing.cpp?rev=193274&r1=193273&r2=193274&view=diff
==============================================================================
--- cfe/trunk/test/Parser/DelayedTemplateParsing.cpp (original)
+++ cfe/trunk/test/Parser/DelayedTemplateParsing.cpp Wed Oct 23 16:31:20 2013
@@ -114,3 +114,10 @@ void LLVMBuildStructGEP() { CreateConstI
 
 }
 
+namespace PR17661 {
+template <typename T>
+constexpr T Fun(T A) { return T(0); }
+
+constexpr int Var = Fun(20);
+}
+





More information about the cfe-commits mailing list