From 5cfe2e319cd4f97afc16795de1b9ba503f05138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 9 Nov 2020 20:44:46 +0100 Subject: [PATCH] Clang import: Fix Variable::isRValueReference --- lib/symboldatabase.cpp | 2 ++ test/testclangimport.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 0bbb49de4..b616b659c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1848,6 +1848,8 @@ Variable::Variable(const Token *name_, const std::string &clangType, const Token if (endsWith(clangType, " &", 2)) setFlag(fIsReference, true); + else if (endsWith(clangType, " &&", 3)) + setFlag(fIsRValueRef, true); std::string::size_type pos = clangType.find("["); if (pos != std::string::npos) { diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 53116278e..4c0e86839 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -108,6 +108,7 @@ private: TEST_CASE(symbolDatabaseFunction3); TEST_CASE(symbolDatabaseFunctionConst); TEST_CASE(symbolDatabaseVariableRef); + TEST_CASE(symbolDatabaseVariableRRef); TEST_CASE(symbolDatabaseNodeType1); TEST_CASE(valueFlow1); @@ -1072,6 +1073,27 @@ private: ASSERT(refVar->isReference()); } + void symbolDatabaseVariableRRef() { + const char clang[] = "`-FunctionDecl 0x1a40df0 <3.cpp:1:1, line:4:1> line:1:6 foo 'void ()'\n" + " `-CompoundStmt 0x1a41180 \n" + " |-DeclStmt 0x1a40f58 \n" + " | `-VarDecl 0x1a40ef0 col:7 used x 'int'\n" + " `-DeclStmt 0x1a41168 \n" + " `-VarDecl 0x1a40fb8 col:9 ref 'int &&' cinit\n" + " `-ExprWithCleanups 0x1a410f8 'int' xvalue\n" + " `-MaterializeTemporaryExpr 0x1a41098 'int' xvalue extended by Var 0x1a40fb8 'ref' 'int &&'\n" + " `-BinaryOperator 0x1a41078 'int' '+'\n" + " |-ImplicitCastExpr 0x1a41060 'int' \n" + " | `-DeclRefExpr 0x1a41020 'int' lvalue Var 0x1a40ef0 'x' 'int'\n" + " `-IntegerLiteral 0x1a41040 'int' 1\n"; + + ASSERT_EQUALS("void foo ( ) { int x@1 ; int && ref@2 = x@1 + 1 ; }", parse(clang)); + + GET_SYMBOL_DB(clang); + const Variable *refVar = db->variableList().back(); + ASSERT(refVar->isRValueReference()); + } + 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"