From 244e29160588e9513e941ee4f805561137bd0b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Feb 2020 18:56:25 +0100 Subject: [PATCH] Fixed #9640 (clang import: reference parameter) --- lib/symboldatabase.cpp | 3 +++ test/testclangimport.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 0ac322125..bc7a52ca4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1753,6 +1753,9 @@ Variable::Variable(const Token *name_, const std::string &clangType, const Token if (start && start->str() == "static") setFlag(fIsStatic, true); + if (endsWith(clangType, " &", 2)) + setFlag(fIsReference, true); + std::string::size_type pos = clangType.find("["); if (pos != std::string::npos) { setFlag(fIsArray, true); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index dbf8b9f8a..ed48d6ff4 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -94,6 +94,7 @@ private: TEST_CASE(symbolDatabaseEnum1); TEST_CASE(symbolDatabaseFunction1); TEST_CASE(symbolDatabaseFunction2); + TEST_CASE(symbolDatabaseFunction3); TEST_CASE(symbolDatabaseNodeType1); TEST_CASE(valueFlow1); @@ -931,6 +932,23 @@ private: ASSERT_EQUALS(0, (long long)func->getArgumentVar(1)->nameToken()); } + void symbolDatabaseFunction3() { // #9640 + const char clang[] = "`-FunctionDecl 0x238fcd8 <9640.cpp:1:1, col:26> col:6 used bar 'bool (const char, int &)'\n" + " |-ParmVarDecl 0x238fb10 col:20 'const char'\n" + " |-ParmVarDecl 0x238fbc0 col:26 'int &'\n" + " `-CompoundStmt 0x3d45c48 \n"; + + GET_SYMBOL_DB(clang); + + // There is a function foo that has 2 arguments + ASSERT_EQUALS(1, db->functionScopes.size()); + const Scope *scope = db->functionScopes[0]; + const Function *func = scope->function; + ASSERT_EQUALS(2, func->argCount()); + ASSERT_EQUALS(false, func->getArgumentVar(0)->isReference()); + ASSERT_EQUALS(true, func->getArgumentVar(1)->isReference()); + } + void symbolDatabaseNodeType1() { const char clang[] = "`-FunctionDecl 0x32438c0 line:5:6 foo 'a::b (a::b)'\n" " |-ParmVarDecl 0x32437b0 col:15 used i 'a::b':'long'\n"