[PATCH] D87030: Adapt CastExpr::getSubExprAsWritten to ConstantExpr
Stephan Bergmann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 12 00:41:18 PST 2021
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG215ed9b33ccb: Adapt CastExpr::getSubExprAsWritten to ConstantExpr (authored by sberg).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87030/new/
https://reviews.llvm.org/D87030
Files:
clang/lib/AST/Expr.cpp
clang/unittests/Tooling/CastExprTest.cpp
Index: clang/unittests/Tooling/CastExprTest.cpp
===================================================================
--- clang/unittests/Tooling/CastExprTest.cpp
+++ clang/unittests/Tooling/CastExprTest.cpp
@@ -34,4 +34,24 @@
"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);
+}
+
}
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1765,7 +1765,7 @@
// subexpression describing the call; strip it off.
if (E->getCastKind() == CK_ConstructorConversion)
SubExpr =
- skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr)->getArg(0));
+ skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr->IgnoreImplicit())->getArg(0));
else if (E->getCastKind() == CK_UserDefinedConversion) {
assert((isa<CXXMemberCallExpr>(SubExpr) ||
isa<BlockExpr>(SubExpr)) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87030.316010.patch
Type: text/x-patch
Size: 1722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210112/f130b598/attachment.bin>
More information about the cfe-commits
mailing list