From 8f3f86223993f7aecfc68ea2b3e9fbd108795c9a Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Mon, 11 Oct 2021 14:14:29 +0200 Subject: [PATCH 1/2] Added `consteval` test and fixed lambda in `static_assert`. --- CodeGenerator.cpp | 2 ++ tests/ConstevalTest.cpp | 17 ++++++++++++ tests/ConstevalTest.expect | 55 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/ConstevalTest.cpp create mode 100644 tests/ConstevalTest.expect diff --git a/CodeGenerator.cpp b/CodeGenerator.cpp index fbd8f65c..93b0f3b2 100644 --- a/CodeGenerator.cpp +++ b/CodeGenerator.cpp @@ -2436,6 +2436,8 @@ void CodeGenerator::InsertArg(const AccessSpecDecl* stmt) void CodeGenerator::InsertArg(const StaticAssertDecl* stmt) { + LAMBDA_SCOPE_HELPER(CallExpr); + if(!stmt->isFailed()) { mOutputFormatHelper.Append("/* PASSED: "sv); } else { diff --git a/tests/ConstevalTest.cpp b/tests/ConstevalTest.cpp new file mode 100644 index 00000000..877887d2 --- /dev/null +++ b/tests/ConstevalTest.cpp @@ -0,0 +1,17 @@ +// cmdline:-std=c++20 + +consteval bool ConstantFun() +{ + return true; +} + +static_assert(ConstantFun()); + +struct Test { + consteval bool Fun() { return true; } +}; + +static_assert(Test{}.Fun()); + +static_assert([]() consteval { return true; }()); + diff --git a/tests/ConstevalTest.expect b/tests/ConstevalTest.expect new file mode 100644 index 00000000..0e068e56 --- /dev/null +++ b/tests/ConstevalTest.expect @@ -0,0 +1,55 @@ +// cmdline:-std=c++20 + +inline consteval bool ConstantFun() +{ + return true; +} + + +/* PASSED: static_assert(ConstantFun()); */ + + +struct Test +{ + inline consteval bool Fun() + { + return true; + } + +}; + + + +/* PASSED: static_assert(Test{}.Fun()); */ + + + +class __lambda_16_15 +{ + public: + inline consteval bool operator()() const + { + return true; + } + + using retType_16_15 = bool (*)(); + inline /*constexpr */ operator retType_16_15 () const noexcept + { + return __invoke; + }; + + private: + static inline bool __invoke() + { + return true; + } + + + public: + // /*constexpr */ __lambda_16_15() = default; + +} __lambda_16_15{}; + +/* PASSED: static_assert(__lambda_16_15.operator()()); */ + + From ea6271719e27fd3be104e7b3c137e90639df6ccf Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Tue, 12 Oct 2021 09:03:47 +0200 Subject: [PATCH 2/2] Added missing test for constraint auto paramters of a lambda. --- tests/ConstraintAutoParameterTest.cpp | 10 ++++++ tests/ConstraintAutoParameterTest.expect | 40 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/ConstraintAutoParameterTest.cpp create mode 100644 tests/ConstraintAutoParameterTest.expect diff --git a/tests/ConstraintAutoParameterTest.cpp b/tests/ConstraintAutoParameterTest.cpp new file mode 100644 index 00000000..875b60c8 --- /dev/null +++ b/tests/ConstraintAutoParameterTest.cpp @@ -0,0 +1,10 @@ +// cmdline:-std=c++20 + +template +concept C = true; + +auto lambda = [](C auto container) { }; + +int main() { + lambda(4); +} diff --git a/tests/ConstraintAutoParameterTest.expect b/tests/ConstraintAutoParameterTest.expect new file mode 100644 index 00000000..d72656a3 --- /dev/null +++ b/tests/ConstraintAutoParameterTest.expect @@ -0,0 +1,40 @@ +// cmdline:-std=c++20 + +template +concept C = true; + + +class __lambda_6_15 +{ + public: + template + inline /*constexpr */ auto operator()(type_parameter_0_0 container) const + { + } + + #ifdef INSIGHTS_USE_TEMPLATE + template<> + inline /*constexpr */ void operator()(int container) const + { + } + #endif + + private: + template + static inline auto __invoke(type_parameter_0_0 container) + { + } + + public: + // /*constexpr */ __lambda_6_15() = default; + +}; + +__lambda_6_15 lambda = __lambda_6_15{}; + + +int main() +{ + lambda.operator()(4); +} +