forked from OSchip/llvm-project
Adapt CastExpr::getSubExprAsWritten to ConstantExpr
Differential Revision: https://reviews.llvm.org/D87030
This commit is contained in:
parent
1cc5235712
commit
215ed9b33c
|
@ -1765,7 +1765,7 @@ Expr *CastExpr::getSubExprAsWritten() {
|
||||||
// subexpression describing the call; strip it off.
|
// subexpression describing the call; strip it off.
|
||||||
if (E->getCastKind() == CK_ConstructorConversion)
|
if (E->getCastKind() == CK_ConstructorConversion)
|
||||||
SubExpr =
|
SubExpr =
|
||||||
skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr)->getArg(0));
|
skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr->IgnoreImplicit())->getArg(0));
|
||||||
else if (E->getCastKind() == CK_UserDefinedConversion) {
|
else if (E->getCastKind() == CK_UserDefinedConversion) {
|
||||||
assert((isa<CXXMemberCallExpr>(SubExpr) ||
|
assert((isa<CXXMemberCallExpr>(SubExpr) ||
|
||||||
isa<BlockExpr>(SubExpr)) &&
|
isa<BlockExpr>(SubExpr)) &&
|
||||||
|
|
|
@ -34,4 +34,24 @@ TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) {
|
||||||
"S1 f(S2 s) { return static_cast<S1>(s); }\n");
|
"S1 f(S2 s) { return static_cast<S1>(s); }\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that getSubExprAsWritten looks through a ConstantExpr in a scenario
|
||||||
|
// like
|
||||||
|
//
|
||||||
|
// CXXFunctionalCastExpr functional cast to struct S <ConstructorConversion>
|
||||||
|
// `-ConstantExpr 'S'
|
||||||
|
// |-value: Struct
|
||||||
|
// `-CXXConstructExpr 'S' 'void (int)'
|
||||||
|
// `-IntegerLiteral 'int' 0
|
||||||
|
TEST(CastExprTest, GetSubExprAsWrittenThroughConstantExpr) {
|
||||||
|
CastExprVisitor Visitor;
|
||||||
|
Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) {
|
||||||
|
auto *Sub = Expr->getSubExprAsWritten();
|
||||||
|
EXPECT_TRUE(isa<IntegerLiteral>(Sub))
|
||||||
|
<< "Expected IntegerLiteral, but saw " << Sub->getStmtClassName();
|
||||||
|
};
|
||||||
|
Visitor.runOver("struct S { consteval S(int) {} };\n"
|
||||||
|
"S f() { return S(0); }\n",
|
||||||
|
CastExprVisitor::Lang_CXX2a);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue