forked from qt-creator/qt-creator
ClangCodeModel: Relax check for const-ness
... when detecting output arguments with clangd. This should lead to fewer false positives. We plan to handle false negatives on a case-by-case basis (rather than the other way around). Change-Id: I541b418927dc410c2ea4ea9f6c1b5a7bd291a1a8 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2605,8 +2605,6 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
|
|||||||
const QList<AstNode> path = getAstPath(ast, range);
|
const QList<AstNode> path = getAstPath(ast, range);
|
||||||
if (path.size() < 2)
|
if (path.size() < 2)
|
||||||
return false;
|
return false;
|
||||||
if (path.last().hasConstType())
|
|
||||||
return false;
|
|
||||||
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
|
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
|
||||||
if (it->kind() == "Call" || it->kind() == "CXXConstruct"
|
if (it->kind() == "Call" || it->kind() == "CXXConstruct"
|
||||||
|| it->kind() == "MemberInitializer") {
|
|| it->kind() == "MemberInitializer") {
|
||||||
@@ -2636,7 +2634,7 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
|
|||||||
|
|
||||||
if (it->kind() == "Lambda")
|
if (it->kind() == "Lambda")
|
||||||
return false;
|
return false;
|
||||||
if (it->kind().endsWith("Cast") && it->hasConstType())
|
if (it->hasConstType())
|
||||||
return false;
|
return false;
|
||||||
if (it->kind() == "Member" && it->arcanaContains("(")
|
if (it->kind() == "Member" && it->arcanaContains("(")
|
||||||
&& !it->arcanaContains("bound member function type")) {
|
&& !it->arcanaContains("bound member function type")) {
|
||||||
|
@@ -1277,6 +1277,8 @@ void ClangdTestHighlighting::test_data()
|
|||||||
<< QList<int>{C_STRING} << 0;
|
<< QList<int>{C_STRING} << 0;
|
||||||
QTest::newRow("user-defined operator call") << 860 << 7 << 860 << 8
|
QTest::newRow("user-defined operator call") << 860 << 7 << 860 << 8
|
||||||
<< QList<int>{C_LOCAL} << 0;
|
<< QList<int>{C_LOCAL} << 0;
|
||||||
|
QTest::newRow("const member as function argument") << 868 << 32 << 868 << 43
|
||||||
|
<< QList<int>{C_FIELD} << 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdTestHighlighting::test()
|
void ClangdTestHighlighting::test()
|
||||||
|
@@ -859,3 +859,13 @@ void useOperator()
|
|||||||
struct S { S& operator++(); } s;
|
struct S { S& operator++(); } s;
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void takesFoo(const Foo &);
|
||||||
|
void constMemberAsFunctionArg()
|
||||||
|
{
|
||||||
|
struct S {
|
||||||
|
S(const Foo& f) : constMember(f) {}
|
||||||
|
void func() { takesFoo(constMember); }
|
||||||
|
const Foo &constMember;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user