<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 17 February 2017 at 18:03, 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:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">On 22 July 2016 at 21:05, Faisal Vali via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: faisalv<br>
Date: Fri Jul 22 23:05:19 2016<br>
New Revision: 276514<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=276514&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=276514&view=rev</a><br>
Log:<br>
[cxx1z-constexpr-lambda] Make a lambda's closure type eligible as a literal-type in C++1z<br>
<br>
<br>
Additionally, for pre-C++1z, instead of forbidding a lambda's closure type from being a literal type through circumlocutorily setting HasNonLiteralTypeFieldsOrBases falsely to true -- handle lambda's more directly in CXXRecordDecl::isLiteral().<br>
<br>
One additional small step towards implementing constexpr-lambdas.<br></blockquote><div><br></div></span><div>I don't know if this problem started with this change, but we now accept this invalid code in C++14 mode:</div><div><br></div><div>constexpr auto a = [] {};</div></div></div></div></blockquote><div><br></div><div>This was a result of two separate bugs. I've fixed one of them, but another remains, and can be observed in this example:</div><div><br></div><div>constexpr int f() { return ([]{}, 0); }</div><div>constexpr int n = f();<br></div><div><br></div><div>This is ill-formed before C++17, and yet we accept it in C++11 mode.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="gmail-h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks to Richard Smith for his review!<br>
<a href="https://reviews.llvm.org/D22662" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2266<wbr>2</a><br>
<br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/De<wbr>clCXX.h<br>
cfe/trunk/test/SemaCXX/cxx1z-c<wbr>onstexpr-lambdas.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/De<wbr>clCXX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=276514&r1=276513&r2=276514&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>AST/DeclCXX.h?rev=276514&r1=<wbr>276513&r2=276514&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/De<wbr>clCXX.h (original)<br>
+++ cfe/trunk/include/clang/AST/De<wbr>clCXX.h Fri Jul 22 23:05:19 2016<br>
@@ -535,11 +535,10 @@ class CXXRecordDecl : public RecordDecl<br>
MethodTyInfo(Info) {<br>
IsLambda = true;<br>
<br>
- // C++11 [expr.prim.lambda]p3:<br>
- // This class type is neither an aggregate nor a literal type.<br>
+ // C++1z [expr.prim.lambda]p4:<br>
+ // This class type is not an aggregate type.<br>
Aggregate = false;<br>
PlainOldData = false;<br>
- HasNonLiteralTypeFieldsOrBases = true;<br>
}<br>
<br>
/// \brief Whether this lambda is known to be dependent, even if its<br>
@@ -1338,11 +1337,15 @@ public:<br>
///<br>
/// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by<br>
/// treating types with trivial default constructors as literal types.<br>
+ ///<br>
+ /// Only in C++1z and beyond, are lambdas literal types.<br>
bool isLiteral() const {<br>
return hasTrivialDestructor() &&<br>
- (isAggregate() || hasConstexprNonCopyMoveConstru<wbr>ctor() ||<br>
- hasTrivialDefaultConstructor()<wbr>) &&<br>
- !hasNonLiteralTypeFieldsOrBas<wbr>es();<br>
+ (!isLambda() || getASTContext().getLangOpts().<wbr>CPlusPlus1z) &&<br>
+ !hasNonLiteralTypeFieldsOrBas<wbr>es() &&<br>
+ (isAggregate() || isLambda() ||<br>
+ hasConstexprNonCopyMoveConstru<wbr>ctor() ||<br>
+ hasTrivialDefaultConstructor()<wbr>);<br>
}<br>
<br>
/// \brief If this record is an instantiation of a member class,<br>
<br>
Modified: cfe/trunk/test/SemaCXX/cxx1z-c<wbr>onstexpr-lambdas.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp?rev=276514&r1=276513&r2=276514&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/SemaCXX/<wbr>cxx1z-constexpr-lambdas.cpp?<wbr>rev=276514&r1=276513&r2=<wbr>276514&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/cxx1z-c<wbr>onstexpr-lambdas.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/cxx1z-c<wbr>onstexpr-lambdas.cpp Fri Jul 22 23:05:19 2016<br>
@@ -1,8 +1,8 @@<br>
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s<br>
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s<br>
-// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions %s<br>
-// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s<br>
+// RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s -DCPP14_AND_EARLIER<br>
<br>
+#ifndef CPP14_AND_EARLIER<br>
namespace test_constexpr_checking {<br>
<br>
namespace ns1 {<br>
@@ -33,4 +33,16 @@ namespace ns3 {<br>
L(3); //expected-note{{non-constexpr function}}<br>
}<br>
<br>
-} // end ns test_constexpr_call<br>
\ No newline at end of file<br>
+} // end ns test_constexpr_call<br>
+<br>
+#endif<br>
+<br>
+namespace test_lambda_is_literal {<br>
+#ifdef CPP14_AND_EARLIER<br>
+//expected-error@+4{{not a literal type}}<br>
+//expected-note@+2{{not an aggregate and has no constexpr constructors}}<br>
+#endif<br>
+auto L = [] { };<br>
+constexpr int foo(decltype(L) l) { return 0; }<br>
+<br>
+}<br>
\ No newline at end of file<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>