I have the following code:
std::for_each(tokens.begin(), tokens.end(), [&](Token& t) { static const std::unordered_map<std::wstring, Wide::Lexer::TokenType> mapping([]() -> std::unordered_map<std::wstring, Wide::Lexer::TokenType> { // Maps strings to TokenType enumerated values std::unordered_map<std::wstring, Wide::Lexer::TokenType> result; // RESERVED WORD result[L"namespace"] = Wide::Lexer::TokenType::Namespace; result[L"for"] = Wide::Lexer::TokenType::For; result[L"while"] = Wide::Lexer::TokenType::While; result[L"do"] = Wide::Lexer::TokenType::Do; result[L"type"] = Wide::Lexer::TokenType::Type; // PUNCTUATION result[L"{"] = Wide::Lexer::TokenType::OpenCurlyBracket; result[L"}"] = Wide::Lexer::TokenType::CloseCurlyBacket; return result; }()); if (mapping.find(t.Codepoints) != mapping.end()) { t.type = mapping.find(t.Codepoints)->second; return; } t.type = Wide::Lexer::TokenType::Identifier; // line 121 });
This is repeated through the list of tokens and, judging by the contents of the code points, assigns them the value from the associated enumeration. If it is not found, specify the value "ID". But this does not compile.
1>Lexer.cpp(121): error C2065: '__this' : undeclared identifier 1>Lexer.cpp(121): error C2227: left of '->Identifier' must point to class/struct/union/generic type
This is a complete error, no warnings, no other errors. What kind? How can I fix this error?
Edit: I did some important refactoring, and I have the same problem in a slightly simpler lambda.
auto end_current_token = [&] { if (current != Wide::Lexer::Token()) { current.type = Wide::Lexer::TokenType::Identifier; // error line if (reserved_words.find(current.Codepoints) != reserved_words.end()) current.type = reserved_words.find(current.Codepoints)->second; if (punctuation.find(current.Codepoints[0]) != punctuation.end()) current.type = punctuation.find(current.Codepoints[0])->second; tokens.push_back(current); current = Wide::Lexer::Token(); } };
I cleaned and rebuilt the project.
I fixed the problem.
auto end_current_token = [&] { if (current != Wide::Lexer::Token()) { // WORKAROUND compiler bug- dead code struct bug_workaround_type { int Identifier; }; bug_workaround_type bug; bug_workaround_type* __this = &bug; current.type = Wide::Lexer::TokenType::Identifier; if (reserved_words.find(current.Codepoints) != reserved_words.end()) current.type = reserved_words.find(current.Codepoints)->second; if (punctuation.find(current.Codepoints[0]) != punctuation.end()) current.type = punctuation.find(current.Codepoints[0])->second; tokens.push_back(current); current = Wide::Lexer::Token(); } };
No really. Now it compiles and works fine.
Puppy source share