Stephan Bergmann | f31b0dc | 2017-06-27 08:19:09 +0000 | [diff] [blame] | 1 | //===- unittest/Tooling/CastExprTest.cpp ----------------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Stephan Bergmann | f31b0dc | 2017-06-27 08:19:09 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "TestVisitor.h" |
| 10 | |
| 11 | using namespace clang; |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | struct CastExprVisitor : TestVisitor<CastExprVisitor> { |
| 16 | std::function<void(ExplicitCastExpr *)> OnExplicitCast; |
| 17 | |
| 18 | bool VisitExplicitCastExpr(ExplicitCastExpr *Expr) { |
| 19 | if (OnExplicitCast) |
| 20 | OnExplicitCast(Expr); |
| 21 | return true; |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) { |
| 26 | CastExprVisitor Visitor; |
| 27 | Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) { |
| 28 | auto Sub = Expr->getSubExprAsWritten(); |
| 29 | EXPECT_TRUE(isa<DeclRefExpr>(Sub)) |
| 30 | << "Expected DeclRefExpr, but saw " << Sub->getStmtClassName(); |
| 31 | }; |
| 32 | Visitor.runOver("struct S1 {};\n" |
| 33 | "struct S2 { operator S1(); };\n" |
| 34 | "S1 f(S2 s) { return static_cast<S1>(s); }\n"); |
| 35 | } |
| 36 | |
| 37 | } |