r191484 - Sema: Respect -fdelayed-template-parsing when parsing constexpr functions

Richard Smith richard at metafoo.co.uk
Wed Oct 23 10:43:58 PDT 2013


On Thu, Sep 26, 2013 at 9:14 PM, David Majnemer <david.majnemer at gmail.com>wrote:

> Author: majnemer
> Date: Thu Sep 26 23:14:12 2013
> New Revision: 191484
>
> URL: http://llvm.org/viewvc/llvm-project?rev=191484&view=rev
> Log:
> 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.
>

I don't think this is the best fix. We should ignore
-fdelayed-template-parsing for constexpr functions, and instead parse them
eagerly. We don't need to delay here, because there's no existing code
which contains a function which is marked constexpr and relies on MSVC
brokenness.

With this fix, constexpr function templates are basically not usable in
constant expressions with -fdelayed-template-parsing (because their bodies
are not available).


> 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.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaExpr.cpp
>     cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=191484&r1=191483&r2=191484&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 26 23:14:12 2013
> @@ -11010,7 +11010,8 @@ 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() || Func->getBody())
> +    if (!(Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing) ||
> +        Func->getBody())
>        return;
>      CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Func);
>      if (!Func->isImplicitlyInstantiable() && (!MD ||
> MD->isUserProvided()))
> @@ -11101,13 +11102,14 @@ void Sema::MarkFunctionReferenced(Source
>        }
>      }
>
> -    if (!AlreadyInstantiated || Func->isConstexpr()) {
> +    if (!AlreadyInstantiated ||
> +        (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing)) {
>        if (isa<CXXRecordDecl>(Func->getDeclContext()) &&
>            cast<CXXRecordDecl>(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.
>
> Modified: cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/DelayedTemplateParsing.cpp?rev=191484&r1=191483&r2=191484&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Parser/DelayedTemplateParsing.cpp (original)
> +++ cfe/trunk/test/Parser/DelayedTemplateParsing.cpp Thu Sep 26 23:14:12
> 2013
> @@ -102,3 +102,15 @@ namespace rdar11700604 {
>    };
>  }
>
> +namespace PR17334 {
> +
> +template <typename = void> struct ArrayRef {
> +  constexpr ArrayRef() {}
> +};
> +template <typename = void> void CreateConstInBoundsGEP2_32() {
> +  ArrayRef<> IdxList;
> +}
> +void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); }
> +
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131023/f983d2a0/attachment.html>


More information about the cfe-commits mailing list