From 4cc32d411abd42b941e2f5267d45c0b72d18d737 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Wed, 5 Dec 2018 12:51:30 +0100 Subject: [PATCH] Clang: Fix highlighting lambda captures This fixes the basic case, but e.g. captures with initializers, e.g. [foo=bar] are not properly reported by libclang and thus "bar" is still not highlighted for this case. Task-number: QTCREATORBUG-15271 Change-Id: I1a2d465f71b0ae1a0406ef9e77d88898e8637958 Reviewed-by: Marco Bubke Reviewed-by: Ivan Donchevskii --- src/tools/clangbackend/source/tokeninfo.cpp | 3 ++- tests/unit/unittest/tokenprocessor-test.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tools/clangbackend/source/tokeninfo.cpp b/src/tools/clangbackend/source/tokeninfo.cpp index b7e40d0327b..de40a954e16 100644 --- a/src/tools/clangbackend/source/tokeninfo.cpp +++ b/src/tools/clangbackend/source/tokeninfo.cpp @@ -372,7 +372,8 @@ void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion) break; case CXCursor_ParmDecl: case CXCursor_VarDecl: - variableKind(cursor); + case CXCursor_VariableRef: + variableKind(cursor.referenced()); break; case CXCursor_DeclRefExpr: identifierKind(cursor.referenced(), Recursion::RecursivePass); diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp index f48d546cb10..3383c9a3b93 100644 --- a/tests/unit/unittest/tokenprocessor-test.cpp +++ b/tests/unit/unittest/tokenprocessor-test.cpp @@ -1697,6 +1697,13 @@ TEST_F(TokenProcessor, DISABLED_NonConstArgumentConstructor) ASSERT_THAT(infos[3], HasMixin(HighlightingType::OutputArgument)); } +TEST_F(TokenProcessor, LambdaLocalVariableCapture) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(442, 47)); + + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::LocalVariable)); +} + Data *TokenProcessor::d; void TokenProcessor::SetUpTestCase()