This is an archive of the discontinued LLVM Phabricator instance.

[constexpr-lambda] Support parsing of constexpr specifier (and its inference) on lambda expressions
ClosedPublic

Authored by faisalv on Nov 21 2015, 1:41 PM.

Details

Reviewers
rsmith
Summary

This patch supports parsing of the constexpr specifier on lambdas - and its inference from the lambda call operator's body.

i.e.
auto L = [] () constexpr { return 5; };
static_assert(L() == 5); // OK

It does not support evaluation of lambda's within constant expressions, which should follow this patch, when approved.

Diff Detail

Event Timeline

faisalv updated this revision to Diff 40873.Nov 21 2015, 1:41 PM
faisalv retitled this revision from to [constexpr-lambda] Support parsing of constexpr specifier (and its inference) on lambda expressions.
faisalv updated this object.
faisalv added a subscriber: cfe-commits.
m-j-w removed a subscriber: m-j-w.
rsmith added inline comments.Mar 4 2016, 7:39 PM
include/clang/Basic/DiagnosticParseKinds.td
772

are -> is

773

Should be CXXPre1zCompat, it's also incompatible with C++11.

775

Any reason not to allow this as an extension in earlier standards?

lib/Parse/ParseExprCXX.cpp
1049

This doesn't look like it'll handle duplicates very well. We should consume and diagnose them, and recover as if they weren't there.

1061

Move this into the caller. It's inconsistent (and doesn't match the function name) to handle this but not 'mutable' here.

lib/Sema/SemaLambda.cpp
1599

Ah, I now see why you were asking about this... :)

I would prefer a Diagnose flag here, but we can make that change later.

test/Parser/cxx1z-constexpr-lambdas.cpp
6

Maybe test __cplusplus > 201402L rather than passing a separate macro?

test/SemaCXX/cxx1z-constexpr-lambdas.cpp
5

You're not using these -D flags for anything; remove them.

faisalv updated this revision to Diff 49889.Mar 5 2016, 9:37 PM
faisalv marked 7 inline comments as done.

Incorporated Richard's feedback:

  • constexpr now elicits an extension warning in pre-cxx1z
  • refactored the function that parses constexpr/mutable and added recovery for duplicates (while emitting a diagnostic)
rsmith added inline comments.Mar 18 2016, 8:49 AM
lib/AST/ExprConstant.cpp
2050

What's the DeclContext of a variable we synthesize to represent an init-capture?

lib/Parse/ParseExprCXX.cpp
1045

No need to mark this inline.

1051

consume -> Consume

1056–1058

Any reason to have an array here rather than two separate variables?

1066

Please add a FixItHint::CreateRemoval(P.getCurToken().getLocation()) here.

1067

Why suppress the diagnostic in this case? If there are three mutable specifiers, I'd like two diagnostics and two FixItHints removing the extra ones. That's what we do for duplicated specifiers in other contexts.

1085

Please spell this as return; instead :)

1090

No need to mark this inline.

faisalv marked 8 inline comments as done.Mar 24 2016, 7:23 PM

Thanks for the review - will submit a updated patch with recommended changes, shortly.

faisalv updated this revision to Diff 51627.Mar 24 2016, 7:26 PM

An updated patch that incorporates Richard's feedback.
Thanks!

rsmith accepted this revision.Mar 25 2016, 6:31 PM
rsmith edited edge metadata.
rsmith added inline comments.
include/clang/Basic/DiagnosticParseKinds.td
769

declspecifier -> decl_specifier

lib/AST/ExprConstant.cpp
2049–2063

I'd prefer to phrase this if/assert arrangement as:

if (!Result) {
  assert(isLambdaCallOperator(...) && (VD->getDeclContext != ...
lib/Parse/ParseExprCXX.cpp
1077

No space before ;.

This revision is now accepted and ready to land.Mar 25 2016, 6:31 PM