Skip to content

Commit

Permalink
Merge pull request #590 from andreasfertig/fixIssue492
Browse files Browse the repository at this point in the history
Fixed #492: Correctly handle lambda in `decltype`.
  • Loading branch information
andreasfertig authored Sep 29, 2023
2 parents 483be7e + 111fc97 commit 7047fbe
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,10 +1506,15 @@ void CodeGenerator::InsertArg(const CXXDeleteExpr* stmt)

void CodeGenerator::InsertConstructorExpr(const auto* stmt)
{
if(P0315Visitor dt{*this}; not dt.TraverseType(stmt->getType())) {
{
CONDITIONAL_LAMBDA_SCOPE_HELPER(Decltype, not isa<DecltypeType>(stmt->getType()))

P0315Visitor dt{*this};
dt.TraverseType(stmt->getType());

if(not mLambdaStack.empty()) {
for(const auto& e : mLambdaStack) {
RETURN_IF(LambdaCallerType::VarDecl == e.callerType());
RETURN_IF((LambdaCallerType::MemberCallExpr == e.callerType()) and isa<DecltypeType>(stmt->getType()));
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Issue492.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// cmdline:-std=c++20

#include <queue>
#include <vector>

void f()
{
std::priority_queue<int,
std::vector<int>,
decltype([](int lhs, int rhs) { return lhs > rhs; })> min_heap;
}
36 changes: 36 additions & 0 deletions tests/Issue492.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// cmdline:-std=c++20

#include <queue>
#include <vector>

void f()
{

class __lambda_10_34
{
public:
inline /*constexpr */ bool operator()(int lhs, int rhs) const
{
return lhs > rhs;
}

using retType_10_34 = bool (*)(int, int);
inline constexpr operator retType_10_34 () const noexcept
{
return __invoke;
};

private:
static inline /*constexpr */ bool __invoke(int lhs, int rhs)
{
return __lambda_10_34{}.operator()(lhs, rhs);
}

public:
// /*constexpr */ __lambda_10_34() = default;

};

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>();
}

20 changes: 20 additions & 0 deletions tests/Issue492_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// cmdline:-std=c++20

template<
class T,
class Container,
class _Compare
> class priority_queue
{
public:
priority_queue(){}
};


void f()
{
priority_queue<int,
float,
decltype([]() { return false; })> min_heap;
}

63 changes: 63 additions & 0 deletions tests/Issue492_2.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// cmdline:-std=c++20

template<class T, class Container, class _Compare>
class priority_queue
{

public:
inline priority_queue()
{
}

};

/* First instantiated from: Issue492_2.cpp:18 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
class priority_queue<int, float, __lambda_18_34>
{

public:
inline priority_queue()
{
}

};

#endif



void f()
{

class __lambda_18_34
{
public:
inline /*constexpr */ bool operator()() const
{
return false;
}

using retType_18_34 = bool (*)();
inline constexpr operator retType_18_34 () const noexcept
{
return __invoke;
};

private:
static inline /*constexpr */ bool __invoke()
{
return __lambda_18_34{}.operator()();
}


public:
// /*constexpr */ __lambda_18_34() = default;

};

priority_queue<int, float, __lambda_18_34> min_heap = priority_queue<int, float, __lambda_18_34>();
}


0 comments on commit 7047fbe

Please sign in to comment.