Summary:
The ASTImporter does currently not handle const_casts. This patch adds the
missing const_cast importer code and the test case that discovered this.
Reviewers: a.sidorin, a_sidorin
Reviewed By: a_sidorin
Subscribers: a_sidorin, martong, cfe-commits
Differential Revision: https://reviews.llvm.org/D50932
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340182
91177308-0d34-0410-b5e6-
96231b3b80d8
return CXXReinterpretCastExpr::Create(
Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
+ } else if (isa<CXXConstCastExpr>(E)) {
+ return CXXConstCastExpr::Create(Importer.getToContext(), ToType, VK, ToOp,
+ ToWritten, ToOperatorLoc, ToRParenLoc,
+ ToAngleBrackets);
} else {
return nullptr;
}
--- /dev/null
+struct A {
+ virtual ~A() {}
+};
+struct B : public A {};
+
+void f() {
+ const A *b = new B();
+ const B *c1 = dynamic_cast<const B *>(b);
+ const B *c2 = static_cast<const B *>(b);
+ const B *c3 = reinterpret_cast<const B *>(b);
+ A *c4 = const_cast<A *>(b);
+}
--- /dev/null
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
+
+// CHECK: CXXDynamicCastExpr
+// CHECK-SAME: dynamic_cast
+// CHECK-SAME: <Dynamic>
+
+// CHECK: CXXStaticCastExpr
+// CHECK-SAME: static_cast
+// CHECK-SAME: <BaseToDerived (A)>
+
+// CHECK: CXXReinterpretCastExpr
+// CHECK-SAME: reinterpret_cast
+// CHECK-SAME: <BitCast>
+
+// CHECK: CXXConstCastExpr
+// CHECK-SAME: const_cast
+// CHECK-SAME: <NoOp>
+
+void expr() {
+ f();
+}
Inv->getLangOpts()->ThreadsafeStatics = false;
Inv->getLangOpts()->AccessControl = false;
Inv->getLangOpts()->DollarIdents = true;
+ // Needed for testing dynamic_cast.
+ Inv->getLangOpts()->RTTI = true;
Inv->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
Inv->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();