Tokenizer::setVarIdNew: Better handling for catch-exception-by-reference
This commit is contained in:
parent
3c1dfc658c
commit
31f8a71f84
|
@ -2854,8 +2854,11 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
|||
*tok = tok2;
|
||||
|
||||
// In executable scopes, references must be assigned
|
||||
if (executableScope && ref && tok2->str() != "=")
|
||||
// Catching by reference is an exception
|
||||
if (executableScope && ref && tok2->str() != "=" &&
|
||||
(tok2->str() != ")" || !Token::simpleMatch(tok2->link()->previous(), "catch"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return bool(typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%"));
|
||||
|
@ -2903,7 +2906,7 @@ void Tokenizer::setVarIdNew()
|
|||
if (tok == _tokens || Token::Match(tok, "[;{},]") ||
|
||||
(tok->str()=="(" && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {")))) {
|
||||
// locate the variable name..
|
||||
const Token *tok2 = (tok == _tokens) ? tok : tok->next();
|
||||
const Token *tok2 = (tok->isName()) ? tok : tok->next();
|
||||
if (!tok2)
|
||||
break;
|
||||
|
||||
|
|
|
@ -225,6 +225,7 @@ private:
|
|||
TEST_CASE(varid_throw);
|
||||
TEST_CASE(varid_unknown_macro); // #2638 - unknown macro is not type
|
||||
TEST_CASE(varid_using); // ticket #3648
|
||||
TEST_CASE(varid_catch);
|
||||
|
||||
TEST_CASE(varidclass1);
|
||||
TEST_CASE(varidclass2);
|
||||
|
@ -3645,6 +3646,19 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
|
||||
}
|
||||
|
||||
void varid_catch() {
|
||||
const char code[] = "void f() {\n"
|
||||
" try { dostuff(); }\n"
|
||||
" catch (exception &e) { }\n"
|
||||
"}";
|
||||
const char expected[] = "\n\n##file 0\n"
|
||||
"1: void f ( ) {\n"
|
||||
"2: try { dostuff ( ) ; }\n"
|
||||
"3: catch ( exception & e@1 ) { }\n"
|
||||
"4: }\n";
|
||||
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
|
||||
}
|
||||
|
||||
void varidclass1() {
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
"class Fred\n"
|
||||
|
|
Loading…
Reference in New Issue