diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2020-10-23 16:37:59 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2020-10-27 11:07:44 +0000 |
commit | 2b32b2e4400c58f464fa44375adc819b4d5a0fd7 (patch) | |
tree | 018043b476b18ade248c2ed54e9e52082d4f7de7 | |
parent | 9c0544c3863da962d07209d823c387066596da1c (diff) |
clangbackend: Provide highlighting for structured bindings
These are reported by libclang as "unexposed declarations".
Fixes: QTCREATORBUG-24769
Change-Id: I7a74b707f4203becabaa74b90758a7b396ee23bd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/tools/clangbackend/source/tokeninfo.cpp | 1 | ||||
-rw-r--r-- | tests/unit/unittest/data/highlightingmarks.cpp | 5 | ||||
-rw-r--r-- | tests/unit/unittest/tokenprocessor-test.cpp | 8 |
3 files changed, 14 insertions, 0 deletions
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() |