forked from qt-creator/qt-creator
ClangCodeModel: Do not offer completion for inaccessible symbols
We should not offer to auto-complete e.g. private members from contexts where they cannot legally be accessed. This is also consistent with the existing behavior of not offering non-const members on const objects. Fixes: QTCREATORBUG-1984 Change-Id: Ic58c1ba2dc0b8023299feebc20bec4f2a5a6ea38 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -132,6 +132,12 @@ static QList<AssistProposalItemInterface *> toAssistProposalItems(
|
||||
if (codeCompletion.text.isEmpty())
|
||||
continue; // It's an OverloadCandidate which has text but no typedText.
|
||||
|
||||
// Don't offer symbols that are not accessible here.
|
||||
if (codeCompletion.availability == CodeCompletion::NotAvailable
|
||||
|| codeCompletion.availability == CodeCompletion::NotAccessible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString name = codeCompletion.completionKind == CodeCompletion::KeywordCompletionKind
|
||||
? CompletionChunksToTextConverter::convertToName(codeCompletion.chunks)
|
||||
: codeCompletion.text.toString();
|
||||
|
@@ -552,6 +552,30 @@ void ClangCodeCompletionTest::testCompleteMembers()
|
||||
QVERIFY(!hasSnippet(t.proposal, "class")); // Snippet
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteMembersFromInside()
|
||||
{
|
||||
ProjectLessCompletionTest t("membercompletion-inside.cpp");
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "publicFunc"));
|
||||
QVERIFY(hasItem(t.proposal, "privateFunc"));
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteMembersFromOutside()
|
||||
{
|
||||
ProjectLessCompletionTest t("membercompletion-outside.cpp");
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "publicFunc"));
|
||||
QVERIFY(!hasItem(t.proposal, "privateFunc"));
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteMembersFromFriend()
|
||||
{
|
||||
ProjectLessCompletionTest t("membercompletion-friend.cpp");
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "publicFunc"));
|
||||
QVERIFY(hasItem(t.proposal, "privateFunc"));
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteFunctions()
|
||||
{
|
||||
ProjectLessCompletionTest t("functionCompletion.cpp");
|
||||
|
@@ -44,6 +44,9 @@ private slots:
|
||||
|
||||
void testCompleteGlobals();
|
||||
void testCompleteMembers();
|
||||
void testCompleteMembersFromInside();
|
||||
void testCompleteMembersFromOutside();
|
||||
void testCompleteMembersFromFriend();
|
||||
void testCompleteFunctions();
|
||||
void testCompleteConstructor();
|
||||
void testCompleteClassAndConstructor();
|
||||
|
@@ -24,5 +24,8 @@
|
||||
<file>dotToArrowCorrection.cpp</file>
|
||||
<file>noDotToArrowCorrectionForFloats.cpp</file>
|
||||
<file>classAndConstructorCompletion.cpp</file>
|
||||
<file>membercompletion-outside.cpp</file>
|
||||
<file>membercompletion-inside.cpp</file>
|
||||
<file>membercompletion-friend.cpp</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -0,0 +1,15 @@
|
||||
static void friendFunc();
|
||||
|
||||
class C {
|
||||
friend void friendFunc();
|
||||
public:
|
||||
void publicFunc() {};
|
||||
|
||||
private:
|
||||
void privateFunc() {}
|
||||
};
|
||||
|
||||
void friendFunc()
|
||||
{
|
||||
C().p /* COMPLETE HERE */
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
class C {
|
||||
public:
|
||||
C() {
|
||||
p /* COMPLETE HERE */
|
||||
}
|
||||
void publicFunc() {};
|
||||
|
||||
private:
|
||||
void privateFunc() {}
|
||||
};
|
||||
|
@@ -0,0 +1,15 @@
|
||||
class C {
|
||||
public:
|
||||
C() {}
|
||||
void publicFunc() {};
|
||||
|
||||
private:
|
||||
void privateFunc() {}
|
||||
};
|
||||
|
||||
void f()
|
||||
{
|
||||
C c;
|
||||
c.p /* COMPLETE HERE */
|
||||
}
|
||||
|
Reference in New Issue
Block a user