Tokenizer::setVarId: better handling of decltype()

This commit is contained in:
Daniel Marjamäki 2020-01-29 17:40:22 +01:00
parent 18124fe248
commit dcee189146
2 changed files with 13 additions and 0 deletions

View File

@ -2996,6 +2996,11 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
if (tok2->isName()) { if (tok2->isName()) {
if (cpp && Token::Match(tok2, "namespace|public|private|protected")) if (cpp && Token::Match(tok2, "namespace|public|private|protected"))
return false; return false;
if (cpp && Token::simpleMatch(tok2, "decltype (")) {
typeCount = 1;
tok2 = tok2->linkAt(1)->next();
continue;
}
if (Token::Match(tok2, "struct|union|enum") || (!c && Token::Match(tok2, "class|typename"))) { if (Token::Match(tok2, "struct|union|enum") || (!c && Token::Match(tok2, "class|typename"))) {
hasstruct = true; hasstruct = true;
typeCount = 0; typeCount = 0;

View File

@ -194,6 +194,8 @@ private:
TEST_CASE(usingNamespace3); TEST_CASE(usingNamespace3);
TEST_CASE(setVarIdStructMembers1); TEST_CASE(setVarIdStructMembers1);
TEST_CASE(decltype1);
} }
std::string tokenize(const char code[], bool simplify = false, const char filename[] = "test.cpp") { std::string tokenize(const char code[], bool simplify = false, const char filename[] = "test.cpp") {
@ -3087,6 +3089,12 @@ private:
"5: }\n"; "5: }\n";
ASSERT_EQUALS(expected, tokenize(code)); ASSERT_EQUALS(expected, tokenize(code));
} }
void decltype1() {
const char code[] = "void foo(int x, decltype(A::b) *p);";
const char expected[] = "1: void foo ( int x@1 , decltype ( A :: b ) * p@2 ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}
}; };
REGISTER_TEST(TestVarID) REGISTER_TEST(TestVarID)