]> granicus.if.org Git - clang/commitdiff
Only filter out names reserved for the implementation (e.g., __blah or
authorDouglas Gregor <dgregor@apple.com>
Wed, 14 Jul 2010 17:44:04 +0000 (17:44 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 14 Jul 2010 17:44:04 +0000 (17:44 +0000)
_Foo) from code-completion results when they come from a system
header.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108338 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/Inputs/reserved.h [new file with mode: 0644]
test/CodeCompletion/ordinary-name.c

index 82861101e832d098522fea93fcd926e0e965fc36..55288750fd5f2dbf43dbded66fd47f4f1d32dd45 100644 (file)
@@ -407,13 +407,16 @@ bool ResultBuilder::isInterestingDecl(NamedDecl *ND,
       return false;
     
     // Filter out names reserved for the implementation (C99 7.1.3, 
-    // C++ [lib.global.names]). Users don't need to see those.
+    // C++ [lib.global.names]) if they come from a system header.
     //
     // FIXME: Add predicate for this.
     if (Id->getLength() >= 2) {
       const char *Name = Id->getNameStart();
       if (Name[0] == '_' &&
-          (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')))
+          (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')) &&
+          (ND->getLocation().isInvalid() ||
+           SemaRef.SourceMgr.isInSystemHeader(
+                          SemaRef.SourceMgr.getSpellingLoc(ND->getLocation()))))
         return false;
     }
   }
diff --git a/test/CodeCompletion/Inputs/reserved.h b/test/CodeCompletion/Inputs/reserved.h
new file mode 100644 (file)
index 0000000..fafe4ac
--- /dev/null
@@ -0,0 +1,2 @@
+typedef int _INTEGER_TYPE;
+typedef float FLOATING_TYPE;
index 1580d01fd3150e576aa4f663c70fc1e634d32542..0807b74b12c4233c1f648c34f655004c763357ba 100644 (file)
@@ -1,10 +1,14 @@
+#include <reserved.h>
 struct X { int x; };
-
 typedef struct t TYPEDEF;
-
+typedef struct t _TYPEDEF;
 void foo() {
   int y;
-  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:6:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -code-completion-at=%s:6:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: _Imaginary
+  // CHECK-CC1-NOT: _INTEGER_TYPE;
+  // CHECK-CC1: _TYPEDEF
+  // CHECK-CC1: FLOATING_TYPE
   // CHECK-CC1: foo
-  // CHECK-CC1: y
   // CHECK-CC1: TYPEDEF
+  // CHECK-CC1: y