Skip to content

Commit 7047fbe

Browse files
Merge pull request #590 from andreasfertig/fixIssue492
Fixed #492: Correctly handle lambda in `decltype`.
2 parents 483be7e + 111fc97 commit 7047fbe

File tree

5 files changed

+137
-2
lines changed

5 files changed

+137
-2
lines changed

CodeGenerator.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,10 +1506,15 @@ void CodeGenerator::InsertArg(const CXXDeleteExpr* stmt)
15061506

15071507
void CodeGenerator::InsertConstructorExpr(const auto* stmt)
15081508
{
1509-
if(P0315Visitor dt{*this}; not dt.TraverseType(stmt->getType())) {
1509+
{
1510+
CONDITIONAL_LAMBDA_SCOPE_HELPER(Decltype, not isa<DecltypeType>(stmt->getType()))
1511+
1512+
P0315Visitor dt{*this};
1513+
dt.TraverseType(stmt->getType());
1514+
15101515
if(not mLambdaStack.empty()) {
15111516
for(const auto& e : mLambdaStack) {
1512-
RETURN_IF(LambdaCallerType::VarDecl == e.callerType());
1517+
RETURN_IF((LambdaCallerType::MemberCallExpr == e.callerType()) and isa<DecltypeType>(stmt->getType()));
15131518
}
15141519
}
15151520
}

tests/Issue492.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// cmdline:-std=c++20
2+
3+
#include <queue>
4+
#include <vector>
5+
6+
void f()
7+
{
8+
std::priority_queue<int,
9+
std::vector<int>,
10+
decltype([](int lhs, int rhs) { return lhs > rhs; })> min_heap;
11+
}

tests/Issue492.expect

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// cmdline:-std=c++20
2+
3+
#include <queue>
4+
#include <vector>
5+
6+
void f()
7+
{
8+
9+
class __lambda_10_34
10+
{
11+
public:
12+
inline /*constexpr */ bool operator()(int lhs, int rhs) const
13+
{
14+
return lhs > rhs;
15+
}
16+
17+
using retType_10_34 = bool (*)(int, int);
18+
inline constexpr operator retType_10_34 () const noexcept
19+
{
20+
return __invoke;
21+
};
22+
23+
private:
24+
static inline /*constexpr */ bool __invoke(int lhs, int rhs)
25+
{
26+
return __lambda_10_34{}.operator()(lhs, rhs);
27+
}
28+
29+
public:
30+
// /*constexpr */ __lambda_10_34() = default;
31+
32+
};
33+
34+
std::priority_queue<int, std::vector<int, std::allocator<int> >, __lambda_10_34> min_heap = std::priority_queue<int, std::vector<int, std::allocator<int> >, __lambda_10_34>();
35+
}
36+

tests/Issue492_2.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// cmdline:-std=c++20
2+
3+
template<
4+
class T,
5+
class Container,
6+
class _Compare
7+
> class priority_queue
8+
{
9+
public:
10+
priority_queue(){}
11+
};
12+
13+
14+
void f()
15+
{
16+
priority_queue<int,
17+
float,
18+
decltype([]() { return false; })> min_heap;
19+
}
20+

tests/Issue492_2.expect

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// cmdline:-std=c++20
2+
3+
template<class T, class Container, class _Compare>
4+
class priority_queue
5+
{
6+
7+
public:
8+
inline priority_queue()
9+
{
10+
}
11+
12+
};
13+
14+
/* First instantiated from: Issue492_2.cpp:18 */
15+
#ifdef INSIGHTS_USE_TEMPLATE
16+
template<>
17+
class priority_queue<int, float, __lambda_18_34>
18+
{
19+
20+
public:
21+
inline priority_queue()
22+
{
23+
}
24+
25+
};
26+
27+
#endif
28+
29+
30+
31+
void f()
32+
{
33+
34+
class __lambda_18_34
35+
{
36+
public:
37+
inline /*constexpr */ bool operator()() const
38+
{
39+
return false;
40+
}
41+
42+
using retType_18_34 = bool (*)();
43+
inline constexpr operator retType_18_34 () const noexcept
44+
{
45+
return __invoke;
46+
};
47+
48+
private:
49+
static inline /*constexpr */ bool __invoke()
50+
{
51+
return __lambda_18_34{}.operator()();
52+
}
53+
54+
55+
public:
56+
// /*constexpr */ __lambda_18_34() = default;
57+
58+
};
59+
60+
priority_queue<int, float, __lambda_18_34> min_heap = priority_queue<int, float, __lambda_18_34>();
61+
}
62+
63+

0 commit comments

Comments
 (0)