summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add -std=c++20 flag, replace C++2a with C++20 throughout the ClangRichard Smith2020-02-191-2/+2
| | | | | | | | | | | | | user interface and documentation, and update __cplusplus for C++20. WG21 considers the C++20 standard to be finished (even though it still has some more steps to pass through in the ISO process). The old flag names are accepted for compatibility, as usual, and we still have lots of references to C++2a in comments and identifiers; those can be cleaned up separately. (cherry picked from commit 24ad121582454e625bdad125c90d9ac0dae948c8)
* Fix test where diagnostics changed in P1668 implementationErich Keane2019-08-191-6/+19
| | | | llvm-svn: 369284
* Implement P1668R1Erich Keane2019-08-191-1/+4
| | | | | | | Allow inline assembly statements in unexecuted branches of constexpr functions. llvm-svn: 369281
* When determining whether a lambda-expression is implicitly constexpr,Richard Smith2019-07-291-0/+29
| | | | | | | | | | | | check the formal rules rather than seeing if the normal checks produce a diagnostic. This fixes the handling of C++2a extensions in lambdas in C++17 mode, as well as some corner cases in earlier language modes where we issue diagnostics for things other than not satisfying the formal constexpr requirements. llvm-svn: 367254
* PR37450: Fix bug that disabled some type checks for variables with deduced ↵Richard Smith2018-05-141-1/+1
| | | | | | | | types. Also improve diagnostic for the case where a type is non-literal because it's a lambda. llvm-svn: 332286
* [AST] Don't track lambda captures when checking a potential constant expression.Erik Pilkington2018-04-051-0/+33
| | | | | | | | Fixes PR36054. Differential revision: https://reviews.llvm.org/D45194 llvm-svn: 329244
* [cxx1z-constexpr-lambda] Implement captures - thus completing implementation ↵Faisal Vali2017-02-161-11/+108
| | | | | | | | | | | | | | of constexpr lambdas. Enable evaluation of captures within constexpr lambdas by using a strategy similar to that used in CodeGen: - when starting evaluation of a lambda's call operator, create a map from VarDecl's to a closure's FieldDecls - every time a VarDecl (or '*this) that represents a capture is encountered while evaluating the expression via the expression evaluator (specifically the LValueEvaluator) in ExprConstant.cpp - it is replaced by the corresponding FieldDecl LValue (an Lvalue-to-Rvalue conversion on this LValue representation then determines the right rvalue when needed). Thanks to Richard Smith and Hubert Tong for their review and feedback! https://reviews.llvm.org/D29748 llvm-svn: 295279
* [cxx1z-constexpr-lambda] Implement constant evaluation of non-capturing ↵Faisal Vali2017-01-091-0/+77
| | | | | | | | | | | | | | | lambda expressions. Add a visitor for lambda expressions to RecordExprEvaluator in ExprConstant.cpp that creates an empty APValue of Struct type to represent the closure object. Additionally, add a LambdaExpr visitor to the TemporaryExprEvaluator that forwards constant evaluation of immediately-called-lambda-expressions to the one in RecordExprEvaluator through VisitConstructExpr. This patch supports: constexpr auto ID = [] (auto a) { return a; }; static_assert(ID(3.14) == 3.14); static_assert([](auto a) { return a + 1; }(10) == 11); Lambda captures are still not supported for constexpr lambdas. llvm-svn: 291416
* [cxx1z-constexpr-lambda] Make conversion function constexpr, and teach the ↵Faisal Vali2017-01-081-0/+37
| | | | | | | | | | | | expression-evaluator to evaluate the static-invoker. This patch has been sitting in review hell since july 2016 and our lack of constexpr lambda support is getting embarrassing (given that I've had a branch that implements the feature (modulo *this capture) for over a year. While in Issaquah I was enjoying shamelessly trying to convince folks of the lie that this was Richard's fault ;) I won't be able to do so in Kona since I won't be attending - so I'm going to aim to have this feature be implemented by then. I'm quite confident of the approach in this patch, which simply maps the static-invoker 'thunk' back to the corresponding call-operator (specialization). Thanks! llvm-svn: 291397
* Fix PR28366: Handle variables from enclosing local scopes more gracefully ↵Faisal Vali2016-11-131-1/+13
| | | | | | | | | | | | | | | | | | during constant expression evaluation. Only look for a variable's value in the constant expression evaluation activation frame, if the variable was indeed declared in that frame, otherwise it might be a constant expression and be usable within a nested local scope or emit an error. void f(char c) { struct X { static constexpr char f() { return c; // error gracefully here as opposed to crashing. } }; int I = X::f(); } llvm-svn: 286748
* [NFC] Rearrange an example-file so the c++14 specific example is on top.Faisal Vali2016-07-311-10/+12
| | | | | | This makes it easier to add C++1z examples to the bottom, just before the #endif. llvm-svn: 277287
* [cxx1z-constexpr-lambda] Make a lambda's closure type eligible as a ↵Faisal Vali2016-07-231-3/+15
| | | | | | | | | | | | | literal-type in C++1z 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(). One additional small step towards implementing constexpr-lambdas. Thanks to Richard Smith for his review! https://reviews.llvm.org/D22662 llvm-svn: 276514
* [Cxx1z-constexpr-lambda-P0170R1] Support parsing of constexpr specifier ↵Faisal Vali2016-03-261-0/+36
(and its inference) on lambda expressions Support the constexpr specifier on lambda expressions - and support its inference from the lambda call operator's body. i.e. auto L = [] () constexpr { return 5; }; static_assert(L() == 5); // OK auto Implicit = [] (auto a) { return a; }; static_assert(Implicit(5) == 5); We do not support evaluation of lambda's within constant expressions just yet. Implementation Strategy: - teach ParseLambdaExpressionAfterIntroducer to expect a constexpr specifier and mark the invented function call operator's declarator's decl-specifier with it; Have it emit fixits for multiple decl-specifiers (mutable or constexpr) in this location. - for cases where constexpr is not explicitly specified, have buildLambdaExpr check whether the invented function call operator satisfies the requirements of a constexpr function, by calling CheckConstexprFunctionDecl/Body. Much obliged to Richard Smith for his patience and his care, in ensuring the code is clang-worthy. llvm-svn: 264513
OpenPOWER on IntegriCloud