diff --git a/clang/test/Index/load-stmts.cpp b/clang/test/Index/load-stmts.cpp index efde248a1df9..bf991e71f815 100644 --- a/clang/test/Index/load-stmts.cpp +++ b/clang/test/Index/load-stmts.cpp @@ -25,6 +25,16 @@ class C : public A, private B { class D : virtual public C, virtual private A {}; +namespace std { + class type_info { }; +} + +void test_exprs(C *c) { + int typeid_marker; + typeid(C); + typeid(c); +} + // RUN: c-index-test -test-load-source all %s | FileCheck %s // CHECK: load-stmts.cpp:1:13: TypedefDecl=T:1:13 (Definition) Extent=[1:13 - 1:14] // CHECK: load-stmts.cpp:2:8: StructDecl=X:2:8 (Definition) Extent=[2:1 - 2:23] @@ -82,4 +92,6 @@ class D : virtual public C, virtual private A {}; // CHECK: load-stmts.cpp:26:7: ClassDecl=D:26:7 (Definition) Extent=[26:1 - 26:49] // CHECK: :0:0: C++ base class specifier=class C:22:7 [access=public isVirtual=true] // CHECK: :0:0: C++ base class specifier=class A:14:7 [access=private isVirtual=true] - +// CHECK: load-stmts.cpp:33:7: VarDecl=typeid_marker:33:7 (Definition) +// CHECK: load-stmts.cpp:34:10: TypeRef=class C:22:7 Extent=[34:10 - 34:11] +// CHECK: load-stmts.cpp:35:10: DeclRefExpr=c:32:20 Extent=[35:10 - 35:11] diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 28751d26c40f..2b3364c77e18 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -384,6 +384,7 @@ public: bool VisitVAArgExpr(VAArgExpr *E); // FIXME: InitListExpr (for the designators) // FIXME: DesignatedInitExpr + bool VisitCXXTypeidExpr(CXXTypeidExpr *E); }; } // end anonymous namespace @@ -1567,6 +1568,17 @@ bool CursorVisitor::VisitVAArgExpr(VAArgExpr *E) { return Visit(MakeCXCursor(E->getSubExpr(), StmtParent, TU)); } +bool CursorVisitor::VisitCXXTypeidExpr(CXXTypeidExpr *E) { + if (E->isTypeOperand()) { + if (TypeSourceInfo *TSInfo = E->getTypeOperandSourceInfo()) + return Visit(TSInfo->getTypeLoc()); + + return false; + } + + return VisitExpr(E); +} + bool CursorVisitor::VisitObjCMessageExpr(ObjCMessageExpr *E) { if (TypeSourceInfo *TSInfo = E->getClassReceiverTypeInfo()) if (Visit(TSInfo->getTypeLoc()))