]> granicus.if.org Git - clang/commitdiff
[index] Index static_assert declarations
authorAlex Lorenz <arphaman@gmail.com>
Thu, 15 Jun 2017 20:50:43 +0000 (20:50 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 15 Jun 2017 20:50:43 +0000 (20:50 +0000)
static_assert declarations have to be visited while indexing so that we can
gather the references to declarations that are present in their assert
expression.

Differential Revision: https://reviews.llvm.org/D33913

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

lib/Index/IndexDecl.cpp
test/Index/Core/index-source.cpp

index 870b4e4fe8255646bd820b41695ee85ae183fb86..c4e9a1a10a36d77f074f91e66feb08fe447719fe 100644 (file)
@@ -682,6 +682,13 @@ public:
   bool VisitImportDecl(const ImportDecl *D) {
     return IndexCtx.importedModule(D);
   }
+
+  bool VisitStaticAssertDecl(const StaticAssertDecl *D) {
+    IndexCtx.indexBody(D->getAssertExpr(),
+                       dyn_cast<NamedDecl>(D->getDeclContext()),
+                       D->getLexicalDeclContext());
+    return true;
+  }
 };
 
 } // anonymous namespace
index 8b049314ffbe35dfecd0c6910598fe41042c71e2..61b7b00463a5669dfc963a411985b5f9b277dc05 100644 (file)
@@ -433,3 +433,19 @@ template<typename T>
 T varDecl = T();
 
 } // end namespace ensureDefaultTemplateParamsAreRecordedOnce
+
+struct StaticAssertRef {
+  static constexpr bool constVar = true;
+};
+
+static_assert(StaticAssertRef::constVar, "index static asserts");
+// CHECK: [[@LINE-1]]:32 | static-property/C++ | constVar | c:@S@StaticAssertRef@constVar | __ZN15StaticAssertRef8constVarE | Ref | rel: 0
+// CHECK: [[@LINE-2]]:15 | struct/C++ | StaticAssertRef | c:@S@StaticAssertRef | <no-cgname> | Ref | rel: 0
+
+void staticAssertInFn() {
+  static_assert(StaticAssertRef::constVar, "index static asserts");
+// CHECK: [[@LINE-1]]:34 | static-property/C++ | constVar | c:@S@StaticAssertRef@constVar | __ZN15StaticAssertRef8constVarE | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | staticAssertInFn | c:@F@staticAssertInFn#
+// CHECK: [[@LINE-3]]:17 | struct/C++ | StaticAssertRef | c:@S@StaticAssertRef | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | staticAssertInFn | c:@F@staticAssertInFn#
+}