Skip to content

Commit 6a4150e

Browse files
Merge pull request #432 from andreasfertig/addConstevalTest
Add consteval test
2 parents 04a0e33 + ea62717 commit 6a4150e

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

CodeGenerator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,8 @@ void CodeGenerator::InsertArg(const AccessSpecDecl* stmt)
24362436

24372437
void CodeGenerator::InsertArg(const StaticAssertDecl* stmt)
24382438
{
2439+
LAMBDA_SCOPE_HELPER(CallExpr);
2440+
24392441
if(!stmt->isFailed()) {
24402442
mOutputFormatHelper.Append("/* PASSED: "sv);
24412443
} else {

tests/ConstevalTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// cmdline:-std=c++20
2+
3+
consteval bool ConstantFun()
4+
{
5+
return true;
6+
}
7+
8+
static_assert(ConstantFun());
9+
10+
struct Test {
11+
consteval bool Fun() { return true; }
12+
};
13+
14+
static_assert(Test{}.Fun());
15+
16+
static_assert([]() consteval { return true; }());
17+

tests/ConstevalTest.expect

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// cmdline:-std=c++20
2+
3+
inline consteval bool ConstantFun()
4+
{
5+
return true;
6+
}
7+
8+
9+
/* PASSED: static_assert(ConstantFun()); */
10+
11+
12+
struct Test
13+
{
14+
inline consteval bool Fun()
15+
{
16+
return true;
17+
}
18+
19+
};
20+
21+
22+
23+
/* PASSED: static_assert(Test{}.Fun()); */
24+
25+
26+
27+
class __lambda_16_15
28+
{
29+
public:
30+
inline consteval bool operator()() const
31+
{
32+
return true;
33+
}
34+
35+
using retType_16_15 = bool (*)();
36+
inline /*constexpr */ operator retType_16_15 () const noexcept
37+
{
38+
return __invoke;
39+
};
40+
41+
private:
42+
static inline bool __invoke()
43+
{
44+
return true;
45+
}
46+
47+
48+
public:
49+
// /*constexpr */ __lambda_16_15() = default;
50+
51+
} __lambda_16_15{};
52+
53+
/* PASSED: static_assert(__lambda_16_15.operator()()); */
54+
55+

tests/ConstraintAutoParameterTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// cmdline:-std=c++20
2+
3+
template<typename T>
4+
concept C = true;
5+
6+
auto lambda = [](C auto container) { };
7+
8+
int main() {
9+
lambda(4);
10+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// cmdline:-std=c++20
2+
3+
template<typename T>
4+
concept C = true;
5+
6+
7+
class __lambda_6_15
8+
{
9+
public:
10+
template<C type_parameter_0_0>
11+
inline /*constexpr */ auto operator()(type_parameter_0_0 container) const
12+
{
13+
}
14+
15+
#ifdef INSIGHTS_USE_TEMPLATE
16+
template<>
17+
inline /*constexpr */ void operator()(int container) const
18+
{
19+
}
20+
#endif
21+
22+
private:
23+
template<C type_parameter_0_0>
24+
static inline auto __invoke(type_parameter_0_0 container)
25+
{
26+
}
27+
28+
public:
29+
// /*constexpr */ __lambda_6_15() = default;
30+
31+
};
32+
33+
__lambda_6_15 lambda = __lambda_6_15{};
34+
35+
36+
int main()
37+
{
38+
lambda.operator()(4);
39+
}
40+

0 commit comments

Comments
 (0)