<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">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-<wbr>project?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><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><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/<wbr>D22662</a><br>
<br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/<wbr>DeclCXX.h<br>
cfe/trunk/test/SemaCXX/cxx1z-<wbr>constexpr-lambdas.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/<wbr>DeclCXX.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-<wbr>project/cfe/trunk/include/<wbr>clang/AST/DeclCXX.h?rev=<wbr>276514&r1=276513&r2=276514&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/<wbr>DeclCXX.h (original)<br>
+++ cfe/trunk/include/clang/AST/<wbr>DeclCXX.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>
- !<wbr>hasNonLiteralTypeFieldsOrBases<wbr>();<br>
+ (!isLambda() || getASTContext().getLangOpts().<wbr>CPlusPlus1z) &&<br>
+ !<wbr>hasNonLiteralTypeFieldsOrBases<wbr>() &&<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-<wbr>constexpr-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-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/cxx1z-constexpr-<wbr>lambdas.cpp?rev=276514&r1=<wbr>276513&r2=276514&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/cxx1z-<wbr>constexpr-lambdas.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/cxx1z-<wbr>constexpr-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">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><br></div></div>