From 2b32b2e4400c58f464fa44375adc819b4d5a0fd7 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 23 Oct 2020 16:37:59 +0200 Subject: [PATCH] clangbackend: Provide highlighting for structured bindings These are reported by libclang as "unexposed declarations". Fixes: QTCREATORBUG-24769 Change-Id: I7a74b707f4203becabaa74b90758a7b396ee23bd Reviewed-by: Christian Stenger --- src/tools/clangbackend/source/tokeninfo.cpp | 1 + tests/unit/unittest/data/highlightingmarks.cpp | 5 +++++ tests/unit/unittest/tokenprocessor-test.cpp | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/src/tools/clangbackend/source/tokeninfo.cpp b/src/tools/clangbackend/source/tokeninfo.cpp index 47b8188986c..6b2e56c8ac1 100644 --- a/src/tools/clangbackend/source/tokeninfo.cpp +++ b/src/tools/clangbackend/source/tokeninfo.cpp @@ -374,6 +374,7 @@ void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion) case CXCursor_ParmDecl: case CXCursor_VarDecl: case CXCursor_VariableRef: + case CXCursor_UnexposedDecl: // structured bindings; see https://reviews.llvm.org/D78213 variableKind(cursor.referenced()); break; case CXCursor_DeclRefExpr: diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp index 33dfbe91dec..346071dea15 100644 --- a/tests/unit/unittest/data/highlightingmarks.cpp +++ b/tests/unit/unittest/data/highlightingmarks.cpp @@ -731,3 +731,8 @@ class Property { ) }; + +void structuredBindingTest() { + const int a[] = {1, 2}; + const auto [x, y] = a; +} diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp index f74fb0dbedd..62a84af59d0 100644 --- a/tests/unit/unittest/tokenprocessor-test.cpp +++ b/tests/unit/unittest/tokenprocessor-test.cpp @@ -1759,6 +1759,14 @@ TEST_F(TokenProcessor, TemplateAlias) ASSERT_THAT(infos[0], HasTwoTypes(HighlightingType::Type, HighlightingType::TypeAlias)); } +TEST_F(TokenProcessor, StructuredBinding) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(737, 23)); + + ASSERT_THAT(infos[3], IsHighlightingMark(737u, 17u, 1u, HighlightingType::LocalVariable)); + ASSERT_THAT(infos[5], IsHighlightingMark(737u, 20u, 1u, HighlightingType::LocalVariable)); +} + Data *TokenProcessor::d; void TokenProcessor::SetUpTestCase()