summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2018-04-17 09:55:58 +0200
committerNikolai Kosjar <nikolai.kosjar@qt.io>2018-04-20 12:55:51 +0000
commit87e0f4d21cd89aaaab7eeb244aaba1fa8dac259a (patch)
tree7e5bcccc3a1410870981dc8cb9b3f5b084e74eef
parent2408485cceff289e018df684683a22f301b04c71 (diff)
[backported/clang-7][libclang] Only mark CXCursors for explicit attributes with a type
------------------------------------------------------------------------- * https://reviews.llvm.org/D38615 * Fixes highlighting of classes e.g. in Qt Creator's texteditor.cpp. ------------------------------------------------------------------------- All attributes have a source range associated with it. However, implicit attributes are added by the compiler, and not added because the user wrote something in the input. So no token type should be set to CXCursor_*Attr. The problem was visible when a class gets marked by e.g. MSInheritanceAttr, which has the full CXXRecordDecl's range as its own range. The effect of marking that range as CXCursor_UnexposedAttr was that all cursors for the record decl, including all child decls, would become CXCursor_UnexposedAttr. Change-Id: If447dd6f21611adff8eaa2752eba2109e2f7ef35 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
-rw-r--r--test/Index/annotate-tokens-unexposed.cpp20
-rw-r--r--tools/libclang/CIndex.cpp2
2 files changed, 21 insertions, 1 deletions
diff --git a/test/Index/annotate-tokens-unexposed.cpp b/test/Index/annotate-tokens-unexposed.cpp
new file mode 100644
index 0000000000..74e04062da
--- /dev/null
+++ b/test/Index/annotate-tokens-unexposed.cpp
@@ -0,0 +1,20 @@
+// RUN: c-index-test -test-annotate-tokens=%s:1:1:16:1 %s -target x86_64-pc-windows-msvc | FileCheck %s
+class Foo
+{
+public:
+ void step(int v);
+ Foo();
+};
+
+void bar()
+{
+ // Introduce a MSInheritanceAttr node on the CXXRecordDecl for Foo. The
+ // existence of this attribute should not mark all cursors for tokens in
+ // Foo as UnexposedAttr.
+ &Foo::step;
+}
+
+Foo::Foo()
+{}
+
+// CHECK-NOT: UnexposedAttr=
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index bd2e4bc8d2..f682d6de01 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -1796,7 +1796,7 @@ bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
bool CursorVisitor::VisitAttributes(Decl *D) {
for (const auto *I : D->attrs())
- if (Visit(MakeCXCursor(I, D, TU)))
+ if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU)))
return true;
return false;