r318292 - [libclang] Fix cursors for in-class initializer of field declarations

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 04:20:41 PST 2017


Author: d0k
Date: Wed Nov 15 04:20:41 2017
New Revision: 318292

URL: http://llvm.org/viewvc/llvm-project?rev=318292&view=rev
Log:
[libclang] Fix cursors for in-class initializer of field declarations

Fixes PR33745.

Patch by Nikolai Kosjar!

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

Modified:
    cfe/trunk/test/Index/get-cursor.cpp
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/test/Index/get-cursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/get-cursor.cpp?rev=318292&r1=318291&r2=318292&view=diff
==============================================================================
--- cfe/trunk/test/Index/get-cursor.cpp (original)
+++ cfe/trunk/test/Index/get-cursor.cpp Wed Nov 15 04:20:41 2017
@@ -152,6 +152,11 @@ void f_dynamic_noexcept_none() throw();
 void f_dynamic_noexcept() throw(int);
 void f_dynamic_noexcept_any() throw(...);
 
+enum EnumType { Enumerator };
+struct Z {
+    EnumType e = Enumerator;
+};
+
 // RUN: c-index-test -cursor-at=%s:6:4 %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s
 // CHECK-COMPLETION-1: CXXConstructor=X:6:3
 // CHECK-COMPLETION-1-NEXT: Completion string: {TypedText X}{LeftParen (}{Placeholder int}{Comma , }{Placeholder int}{RightParen )}
@@ -275,3 +280,6 @@ void f_dynamic_noexcept_any() throw(...)
 // CHECK-FORRANGE: 141:18 DeclRefExpr=coll:140:20 Extent=[141:18 - 141:22] Spelling=coll ([141:18 - 141:22])
 // CHECK-FORRANGE: 142:11 DeclRefExpr=lv:141:13 Extent=[142:11 - 142:13] Spelling=lv ([142:11 - 142:13])
 
+// RUN: c-index-test -cursor-at=%s:157:18 -std=c++11 %s | FileCheck -check-prefix=CHECK-INCLASSINITIALIZER %s
+// CHECK-INCLASSINITIALIZER: 157:18 DeclRefExpr=Enumerator:155:17 Extent=[157:18 - 157:28] Spelling=Enumerator ([157:18 - 157:28])
+

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=318292&r1=318291&r2=318292&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Nov 15 04:20:41 2017
@@ -877,6 +877,9 @@ bool CursorVisitor::VisitFieldDecl(Field
   if (Expr *BitWidth = D->getBitWidth())
     return Visit(MakeCXCursor(BitWidth, StmtParent, TU, RegionOfInterest));
 
+  if (Expr *Init = D->getInClassInitializer())
+    return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
+
   return false;
 }
 




More information about the cfe-commits mailing list