<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 23, 2013 at 10:43 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>On Thu, Sep 26, 2013 at 9:14 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>

</div><div class="gmail_extra"><div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: majnemer<br>
Date: Thu Sep 26 23:14:12 2013<br>
New Revision: 191484<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=191484&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=191484&view=rev</a><br>
Log:<br>
Sema: Respect -fdelayed-template-parsing when parsing constexpr functions<br>
<br>
Functions declared as constexpr must have their parsing delayed in<br>
-fdelayed-template-parsing mode so as not to upset later template<br>
instantiation.<br></blockquote><div><br></div></div><div>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.</div>


<div><br></div><div>With this fix, constexpr function templates are basically not usable in constant expressions with -fdelayed-template-parsing (because their bodies are not available).</div></div></div></div></blockquote>
<div><br></div><div>Good call, I've implemented this approach in r193274.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

N.B. My reading of the standard makes it seem like delayed template<br>
parsing is at odds with constexpr.  We may want to make refinements in<br>
other places in clang to make constexpr play nicer with this feature.<br>
<br>
This fixes PR17334.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaExpr.cpp<br>
    cfe/trunk/test/Parser/DelayedTemplateParsing.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=191484&r1=191483&r2=191484&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=191484&r1=191483&r2=191484&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 26 23:14:12 2013<br>
@@ -11010,7 +11010,8 @@ void Sema::MarkFunctionReferenced(Source<br>
     // However, they cannot be referenced if they are deleted, and they are<br>
     // deleted whenever the implicit definition of the special member would<br>
     // fail.<br>
-    if (!Func->isConstexpr() || Func->getBody())<br>
+    if (!(Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing) ||<br>
+        Func->getBody())<br>
       return;<br>
     CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Func);<br>
     if (!Func->isImplicitlyInstantiable() && (!MD || MD->isUserProvided()))<br>
@@ -11101,13 +11102,14 @@ void Sema::MarkFunctionReferenced(Source<br>
       }<br>
     }<br>
<br>
-    if (!AlreadyInstantiated || Func->isConstexpr()) {<br>
+    if (!AlreadyInstantiated ||<br>
+        (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing)) {<br>
       if (isa<CXXRecordDecl>(Func->getDeclContext()) &&<br>
           cast<CXXRecordDecl>(Func->getDeclContext())->isLocalClass() &&<br>
           ActiveTemplateInstantiations.size())<br>
         PendingLocalImplicitInstantiations.push_back(<br>
             std::make_pair(Func, PointOfInstantiation));<br>
-      else if (Func->isConstexpr())<br>
+      else if (Func->isConstexpr() && !getLangOpts().DelayedTemplateParsing)<br>
         // Do not defer instantiations of constexpr functions, to avoid the<br>
         // expression evaluator needing to call back into Sema if it sees a<br>
         // call to such a function.<br>
<br>
Modified: cfe/trunk/test/Parser/DelayedTemplateParsing.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/DelayedTemplateParsing.cpp?rev=191484&r1=191483&r2=191484&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/DelayedTemplateParsing.cpp?rev=191484&r1=191483&r2=191484&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/test/Parser/DelayedTemplateParsing.cpp (original)<br>
+++ cfe/trunk/test/Parser/DelayedTemplateParsing.cpp Thu Sep 26 23:14:12 2013<br>
@@ -102,3 +102,15 @@ namespace rdar11700604 {<br>
   };<br>
 }<br>
<br>
+namespace PR17334 {<br>
+<br>
+template <typename = void> struct ArrayRef {<br>
+  constexpr ArrayRef() {}<br>
+};<br>
+template <typename = void> void CreateConstInBoundsGEP2_32() {<br>
+  ArrayRef<> IdxList;<br>
+}<br>
+void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); }<br>
+<br>
+}<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>