blob: 5310c2125472446457c8dfc6ca9ca54fbd87cfae [file] [log] [blame]
Stephan Bergmannf31b0dc2017-06-27 08:19:09 +00001//===- 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
12using namespace clang;
13
14namespace {
15
16struct 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
26TEST(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}