Fix syntax error with lambda captures (#1954)
* Fix syntax error with lambda captures * Fix issue when using initializer in lambdas
This commit is contained in:
parent
afce191db1
commit
5801fb26f0
|
@ -9250,7 +9250,8 @@ void Tokenizer::findGarbageCode() const
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
if (Token::Match(tok, "[+-] [;,)]}]") && !(isCPP() && Token::Match(tok->previous(), "operator [+-] ;")))
|
if (Token::Match(tok, "[+-] [;,)]}]") && !(isCPP() && Token::Match(tok->previous(), "operator [+-] ;")))
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
if (Token::simpleMatch(tok, ",")) {
|
if (Token::simpleMatch(tok, ",") &&
|
||||||
|
!Token::Match(tok->tokAt(-2), "[ = , &|%name%")) {
|
||||||
if (Token::Match(tok->previous(), "(|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof|throw|decltype|typeof"))
|
if (Token::Match(tok->previous(), "(|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof|throw|decltype|typeof"))
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
if (Token::Match(tok->next(), ")|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&"))
|
if (Token::Match(tok->next(), ")|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&"))
|
||||||
|
|
|
@ -459,6 +459,7 @@ private:
|
||||||
TEST_CASE(checkEnableIf);
|
TEST_CASE(checkEnableIf);
|
||||||
TEST_CASE(checkTemplates);
|
TEST_CASE(checkTemplates);
|
||||||
TEST_CASE(checkNamespaces);
|
TEST_CASE(checkNamespaces);
|
||||||
|
TEST_CASE(checkLambdas);
|
||||||
|
|
||||||
// #9052
|
// #9052
|
||||||
TEST_CASE(noCrash1);
|
TEST_CASE(noCrash1);
|
||||||
|
@ -7834,6 +7835,13 @@ private:
|
||||||
ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}"))
|
ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkLambdas() {
|
||||||
|
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, &i] {}; }"))
|
||||||
|
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i] {}; }"))
|
||||||
|
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i = std::move(i)] {}; }"))
|
||||||
|
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, i = std::move(i)] {}; }"))
|
||||||
|
}
|
||||||
|
|
||||||
void noCrash1() {
|
void noCrash1() {
|
||||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||||
"struct A {\n"
|
"struct A {\n"
|
||||||
|
|
Loading…
Reference in New Issue