Skip to content

Commit

Permalink
Merge pull request #43 from andreasfertig/fixIssue41
Browse files Browse the repository at this point in the history
Fixed Issue #41: Segfault with generic lambda.
  • Loading branch information
Andreas Fertig authored Jul 14, 2018
2 parents c6adec6 + 85a0c03 commit e74fd6d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
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{});
}

0 comments on commit e74fd6d

Please sign in to comment.