From 18124fe248d5108962e0884654e4acf740a2efa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 29 Jan 2020 17:29:28 +0100 Subject: [PATCH] Fixed #9591 (SymbolDatabase: decltype) --- lib/symboldatabase.cpp | 4 ++++ test/testsymboldatabase.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 014400a4d..4d888bad4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3417,6 +3417,10 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s const Token* nameTok = nullptr; do { + if (Token::simpleMatch(tok, "decltype (")) { + tok = tok->linkAt(1)->next(); + continue; + } if (tok != startTok && !nameTok && Token::Match(tok, "( & %var% ) [")) { nameTok = tok->tokAt(2); endTok = nameTok->previous(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d29d5422c..e957b9214 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -219,6 +219,7 @@ private: TEST_CASE(functionArgs13); // #7697 TEST_CASE(functionArgs14); // #9055 TEST_CASE(functionArgs15); // #7159 + TEST_CASE(functionArgs16); // #9591 TEST_CASE(functionImplicitlyVirtual); @@ -2309,6 +2310,21 @@ private: ASSERT_EQUALS(0, method.minArgCount()); } + void functionArgs16() { // #9591 + const char code[] = + "struct A { int var; };\n" + "void foo(int x, decltype(A::var) *&p) {}"; + GET_SYMBOL_DB(code); + ASSERT(db); + const Scope *scope = db->functionScopes.front(); + const Function *func = scope->function; + ASSERT_EQUALS(2, func->argCount()); + const Variable *arg2 = func->getArgumentVar(1); + ASSERT_EQUALS("p", arg2->name()); + ASSERT(arg2->isPointer()); + ASSERT(arg2->isReference()); + } + void functionImplicitlyVirtual() { GET_SYMBOL_DB("class base { virtual void f(); };\n" "class derived : base { void f(); };\n"