Stephan Bergmann | f31b0dc | 2017-06-27 08:19:09 +0000 | [diff] [blame^] | 1 | //===- unittest/Tooling/CastExprTest.cpp ----------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "TestVisitor.h" |
| 11 | |
| 12 | using namespace clang; |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | struct CastExprVisitor : TestVisitor<CastExprVisitor> { |
| 17 | std::function<void(ExplicitCastExpr *)> OnExplicitCast; |
| 18 | |
| 19 | bool VisitExplicitCastExpr(ExplicitCastExpr *Expr) { |
| 20 | if (OnExplicitCast) |
| 21 | OnExplicitCast(Expr); |
| 22 | return true; |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) { |
| 27 | CastExprVisitor Visitor; |
| 28 | Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) { |
| 29 | auto Sub = Expr->getSubExprAsWritten(); |
| 30 | EXPECT_TRUE(isa<DeclRefExpr>(Sub)) |
| 31 | << "Expected DeclRefExpr, but saw " << Sub->getStmtClassName(); |
| 32 | }; |
| 33 | Visitor.runOver("struct S1 {};\n" |
| 34 | "struct S2 { operator S1(); };\n" |
| 35 | "S1 f(S2 s) { return static_cast<S1>(s); }\n"); |
| 36 | } |
| 37 | |
| 38 | } |