From c80c724b5294bc02496c7c89a404dd24eefd5413 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 15 Apr 2021 13:54:02 +0200 Subject: ClangCodeModel: Fix template highlighting bug We need to take into account that the ">>" in constructs such as std::vector> is only one token on the clang side. Change-Id: I90f002ca56f236032f6d39c338593a2ff7590061 Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- tests/unit/unittest/data/highlightingmarks.cpp | 2 ++ tests/unit/unittest/gtest-creator-printing.cpp | 1 + tests/unit/unittest/tokenprocessor-test.cpp | 7 +++++++ 3 files changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp index f3b624f320..8221afc29f 100644 --- a/tests/unit/unittest/data/highlightingmarks.cpp +++ b/tests/unit/unittest/data/highlightingmarks.cpp @@ -769,3 +769,5 @@ template void func(T v) { GlobalVar = 5; } + +static std::vector> pv; diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index cc10dcfa9d..2f0afc841c 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -868,6 +868,7 @@ static const char *highlightingTypeToCStringLiteral(HighlightingType type) RETURN_TEXT_FOR_CASE(TemplateTemplateParameter); RETURN_TEXT_FOR_CASE(AngleBracketOpen); RETURN_TEXT_FOR_CASE(AngleBracketClose); + RETURN_TEXT_FOR_CASE(DoubleAngleBracketClose); RETURN_TEXT_FOR_CASE(TernaryIf); RETURN_TEXT_FOR_CASE(TernaryElse); } diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp index 94e1b83b15..562f852abe 100644 --- a/tests/unit/unittest/tokenprocessor-test.cpp +++ b/tests/unit/unittest/tokenprocessor-test.cpp @@ -1794,6 +1794,13 @@ TEST_F(TokenProcessor, TemplateSeparateDeclDef) ASSERT_THAT(infos[37], IsHighlightingMark(764u, 5u, 9u, HighlightingType::GlobalVariable)); } +TEST_F(TokenProcessor, NestedTemplate) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(773, 44)); + ASSERT_THAT(infos[12], HasTwoTypes(HighlightingType::Punctuation, + HighlightingType::DoubleAngleBracketClose)); +} + Data *TokenProcessor::d; void TokenProcessor::SetUpTestCase() -- cgit v1.2.3