[PATCH] D33913: [index] Index static_assert declarations

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 5 14:07:41 PDT 2017


arphaman created this revision.

static_assert declarations have to be indexed to gather the declaration references in their assert expression.


Repository:
  rL LLVM

https://reviews.llvm.org/D33913

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


Index: test/Index/Core/index-source.cpp
===================================================================
--- test/Index/Core/index-source.cpp
+++ test/Index/Core/index-source.cpp
@@ -433,3 +433,19 @@
 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 at StaticAssertRef@constVar | __ZN15StaticAssertRef8constVarE | Ref | rel: 0
+// CHECK: [[@LINE-2]]:15 | struct/C++ | StaticAssertRef | c:@S at 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 at StaticAssertRef@constVar | __ZN15StaticAssertRef8constVarE | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | staticAssertInFn | c:@F at staticAssertInFn#
+// CHECK: [[@LINE-3]]:17 | struct/C++ | StaticAssertRef | c:@S at StaticAssertRef | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | staticAssertInFn | c:@F at staticAssertInFn#
+}
Index: lib/Index/IndexDecl.cpp
===================================================================
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -682,6 +682,13 @@
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33913.101458.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170605/3192672e/attachment.bin>


More information about the cfe-commits mailing list