From: Benjamin Kramer Date: Wed, 15 Nov 2017 12:20:41 +0000 (+0000) Subject: [libclang] Fix cursors for in-class initializer of field declarations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=818167bc99a0f5538a2676bf876e5c598d1b449b;p=clang [libclang] Fix cursors for in-class initializer of field declarations Fixes PR33745. Patch by Nikolai Kosjar! Differential Revision: https://reviews.llvm.org/D40027 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318292 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/get-cursor.cpp b/test/Index/get-cursor.cpp index 8aa12d5bc3..e997fc493d 100644 --- a/test/Index/get-cursor.cpp +++ b/test/Index/get-cursor.cpp @@ -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]) + diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 2a1b63d83e..74a17d21e0 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -877,6 +877,9 @@ bool CursorVisitor::VisitFieldDecl(FieldDecl *D) { 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; }