forked from qt-creator/qt-creator
ClangCodeModel: Fix mis-detection of class members as operators
The name check was not tight enough. Change-Id: I5d813a29525bd5b5c23ce04f0bd9e5982a36536e Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -3839,10 +3839,18 @@ void ExtraHighlightingResultsCollector::collectFromNode(const AstNode &node)
|
||||
QString detail = node.detail().value_or(QString());
|
||||
const bool isCallToNew = node.kind() == "CXXNew";
|
||||
const bool isCallToDelete = node.kind() == "CXXDelete";
|
||||
if (!isCallToNew && !isCallToDelete
|
||||
&& (!detail.startsWith(operatorPrefix) || detail == operatorPrefix)) {
|
||||
const auto isProperOperator = [&] {
|
||||
if (isCallToNew || isCallToDelete)
|
||||
return true;
|
||||
if (!detail.startsWith(operatorPrefix))
|
||||
return false;
|
||||
if (detail == operatorPrefix)
|
||||
return false;
|
||||
const QChar nextChar = detail.at(operatorPrefix.length());
|
||||
return !nextChar.isLetterOrNumber() && nextChar != '_';
|
||||
};
|
||||
if (!isProperOperator())
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCallToNew && !isCallToDelete)
|
||||
detail.remove(0, operatorPrefix.length());
|
||||
|
@@ -1329,6 +1329,14 @@ void ClangdTestHighlighting::test_data()
|
||||
<< QList<int>{C_FIELD} << 0;
|
||||
QTest::newRow("pass inherited member by value") << 1038 << 21 << 1038 << 26
|
||||
<< QList<int>{C_FIELD} << 0;
|
||||
QTest::newRow("fake operator member declaration") << 1045 << 9 << 1045 << 23
|
||||
<< QList<int>{C_FIELD, C_DECLARATION} << 0;
|
||||
QTest::newRow("fake operator method declaration") << 1046 << 10 << 1046 << 24
|
||||
<< QList<int>{C_FUNCTION, C_DECLARATION} << 0;
|
||||
QTest::newRow("fake operator member access") << 1049 << 8 << 1049 << 22
|
||||
<< QList<int>{C_FIELD} << 0;
|
||||
QTest::newRow("fake operator method call") << 1050 << 8 << 1050 << 22
|
||||
<< QList<int>{C_FUNCTION} << 0;
|
||||
}
|
||||
|
||||
void ClangdTestHighlighting::test()
|
||||
|
@@ -1040,3 +1040,12 @@ template<typename T> class Derived2 : public BaseWithMember2
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct StructWithMisleadingMemberNames {
|
||||
int operatormember;
|
||||
void operatorMethod();
|
||||
};
|
||||
void useStrangeStruct(StructWithMisleadingMemberNames *s) {
|
||||
s->operatormember = 5;
|
||||
s->operatorMethod();
|
||||
}
|
||||
|
Reference in New Issue
Block a user