From f1822ec431cded5e50b69152346794d79976a8b2 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 3 Dec 2018 13:29:17 +0000 Subject: [CodeComplete] Cleanup access checking in code completion Summary: Also fixes a crash (see the added 'accessibility-crash.cpp' test). Reviewers: ioeric, kadircet Reviewed By: kadircet Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55124 llvm-svn: 348135 --- clang/test/CodeCompletion/accessibility-crash.cpp | 23 +++++++ clang/test/CodeCompletion/accessibility.cpp | 73 +++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 clang/test/CodeCompletion/accessibility-crash.cpp create mode 100644 clang/test/CodeCompletion/accessibility.cpp (limited to 'clang/test/CodeCompletion') diff --git a/clang/test/CodeCompletion/accessibility-crash.cpp b/clang/test/CodeCompletion/accessibility-crash.cpp new file mode 100644 index 00000000000..b54f7cea3e2 --- /dev/null +++ b/clang/test/CodeCompletion/accessibility-crash.cpp @@ -0,0 +1,23 @@ +class X { +public: + int pub; +protected: + int prot; +private: + int priv; +}; + +class Y : public X { + int test() { + []() { + + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:1 %s -o - \ + // RUN: | FileCheck %s + // CHECK: priv (InBase,Inaccessible) + // CHECK: prot (InBase) + // CHECK: pub (InBase) + }; + } +}; + + diff --git a/clang/test/CodeCompletion/accessibility.cpp b/clang/test/CodeCompletion/accessibility.cpp new file mode 100644 index 00000000000..754d8228ad4 --- /dev/null +++ b/clang/test/CodeCompletion/accessibility.cpp @@ -0,0 +1,73 @@ +class X { +public: + int pub; +protected: + int prot; +private: + int priv; +}; + +class Unrelated { +public: + static int pub; +protected: + static int prot; +private: + static int priv; +}; + +class Y : public X { + int test() { + this->pub = 10; + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:21:11 %s -o - \ + // RUN: | FileCheck -check-prefix=THIS %s + // THIS: priv (InBase,Inaccessible) + // THIS: prot (InBase) + // THIS: pub (InBase) + // + // Also check implicit 'this->', i.e. complete at the start of the line. + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:21:1 %s -o - \ + // RUN: | FileCheck -check-prefix=THIS %s + + X().pub + 10; + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:32:9 %s -o - \ + // RUN: | FileCheck -check-prefix=X-OBJ %s + // X-OBJ: priv (Inaccessible) + // X-OBJ: prot (Inaccessible) + // X-OBJ: pub : [#int#]pub + + Y().pub + 10; + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:39:9 %s -o - \ + // RUN: | FileCheck -check-prefix=Y-OBJ %s + // Y-OBJ: priv (InBase,Inaccessible) + // Y-OBJ: prot (InBase) + // Y-OBJ: pub (InBase) + + this->X::pub = 10; + X::pub = 10; + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:46:14 %s -o - \ + // RUN: | FileCheck -check-prefix=THIS-BASE %s + // + // THIS-BASE: priv (Inaccessible) + // THIS-BASE: prot : [#int#]prot + // THIS-BASE: pub : [#int#]pub + // + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:47:8 %s -o - \ + // RUN: | FileCheck -check-prefix=THIS-BASE %s + + + this->Unrelated::pub = 10; // a check we don't crash in this cases. + Y().Unrelated::pub = 10; // a check we don't crash in this cases. + Unrelated::pub = 10; + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:59:22 %s -o - \ + // RUN: | FileCheck -check-prefix=UNRELATED %s + // UNRELATED: priv (Inaccessible) + // UNRELATED: prot (Inaccessible) + // UNRELATED: pub : [#int#]pub + // + // RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:60:20 %s -o - \ + // RUN: | FileCheck -check-prefix=UNRELATED %s + // RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:61:16 %s -o - \ + // RUN: | FileCheck -check-prefix=UNRELATED %s + } +}; -- cgit v1.2.3