ClangBackEnd: Fix mis-detection of operator<

Inside the body of a function template, clang reports a different cursor
type for operators in some cases. Make sure we don't mistake such
operator< or operator> as opening or closing a template, respectively.

Fixes: QTCREATORBUG-25596
Change-Id: Ifc357e199ea13e44ac501613639e667c333d48e3
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-04-16 15:38:52 +02:00
parent ee3e4f9e25
commit f307c55eac
3 changed files with 24 additions and 0 deletions

View File

@@ -599,6 +599,7 @@ void TokenInfo::punctuationOrOperatorKind()
if (m_types.mainHighlightingType == HighlightingType::Punctuation
&& m_types.mixinHighlightingTypes.empty()
&& kind != CXCursor_OverloadedDeclRef
&& kind != CXCursor_InclusionDirective
&& kind != CXCursor_PreprocessingDirective) {
const ClangString spelling = m_token->spelling();

View File

@@ -771,3 +771,20 @@ void func(T v) {
}
static std::vector<std::pair<int, int>> pv;
template <class T, long S>
struct vecn
{
T v[S];
};
template <class T, long S>
static inline constexpr vecn<T, S> operator<(vecn<T, S> a, vecn<T, S> b)
{
vecn<T, S> x = vecn<T, S>{};
for(long i = 0; i < S; ++i)
{
x[i] = a[i] < b[i];
}
return x;
}

View File

@@ -1801,6 +1801,12 @@ TEST_F(TokenProcessor, NestedTemplate)
HighlightingType::DoubleAngleBracketClose));
}
TEST_F(TokenProcessor, OperatorInTemplate)
{
const auto infos = translationUnit.tokenInfosInRange(sourceRange(787, 28));
ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Punctuation));
}
Data *TokenProcessor::d;
void TokenProcessor::SetUpTestCase()