mirror of https://github.com/microsoft/clang.git
[ASTImporter] Add test for C++ casts and fix broken const_cast importing.
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
This commit is contained in:
parent
5b14cddec6
commit
ae679b05d3
|
@ -6897,6 +6897,10 @@ Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
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);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
// 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();
|
||||
}
|
|
@ -194,6 +194,8 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
|
|||
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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue