Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue #41: Segfault with generic lambda. #43

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ OutputFormatHelper& CodeGenerator::LambdaScopeHandler::GetBuffer(OutputFormatHel
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const CXXDependentScopeMemberExpr* stmt)
{
InsertArg(stmt->getBase());
const std::string op{stmt->isArrow() ? "->" : "."};

mOutputFormatHelper.Append(op, stmt->getMemberNameInfo().getAsString());
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const CXXForRangeStmt* rangeForStmt)
{
mOutputFormatHelper.OpenScope();
Expand Down Expand Up @@ -1070,7 +1079,12 @@ void CodeGenerator::InsertArg(const CXXOperatorCallExpr* stmt)

// operators in a namespace but outside a class so operator goes first
if(!isCXXMethod) {
mOutputFormatHelper.Append(GetName(*callee), "(");
if(callee) {
mOutputFormatHelper.Append(GetName(*callee), "(");
} else {
InsertArg(stmt->getCallee()->IgnoreImpCasts());
mOutputFormatHelper.Append("(");
}
}

// insert the arguments
Expand Down
1 change: 1 addition & 0 deletions CodeGeneratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ SUPPORTED_STMT(CXXScalarValueInitExpr)
SUPPORTED_STMT(CXXTryStmt)
SUPPORTED_STMT(CXXCatchStmt)
SUPPORTED_STMT(CXXThrowExpr)
SUPPORTED_STMT(CXXDependentScopeMemberExpr)

#undef IGNORED_DECL
#undef IGNORED_STMT
Expand Down
13 changes: 13 additions & 0 deletions tests/Issue41.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
vector<string> v = { "aaa", "bbb", "ccc" };

auto it = std::find_if(begin(v), end(v),
[](const auto & str){ return str == "bbb";} );
}
22 changes: 22 additions & 0 deletions tests/Issue41.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
vector<std::string> v = std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > >{std::initializer_list<std::basic_string<char> >{std::basic_string<char>("aaa"), std::basic_string<char>("bbb"), std::basic_string<char>("ccc")}};

class __lambda_12_26
{
public: inline /*constexpr */ bool operator()(const std::basic_string<char> & str) const
{
return operator==(str, "bbb");
}

};

std::__wrap_iter<std::basic_string<char> *> it = std::find_if(std::begin(v), std::end(v), __lambda_12_26{});
}