[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / unittests / AST / ASTExprTest.cpp
blobec75492ccff8e44a5010a2fd9ca5f86c67ccc0e8
1 //===- unittests/AST/ASTExprTest.cpp --- AST Expr tests -------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains tests for AST Expr related methods.
11 //===----------------------------------------------------------------------===//
13 #include "ASTPrint.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Expr.h"
16 #include "clang/AST/IgnoreExpr.h"
17 #include "clang/ASTMatchers/ASTMatchFinder.h"
18 #include "clang/Tooling/Tooling.h"
19 #include "gtest/gtest.h"
21 using namespace clang;
23 TEST(ASTExpr, IgnoreExprCallbackForwarded) {
24 constexpr char Code[] = "";
25 auto AST = tooling::buildASTFromCodeWithArgs(Code, /*Args=*/{"-std=c++20"});
26 ASTContext &Ctx = AST->getASTContext();
28 auto createIntLiteral = [&](uint32_t Value) -> IntegerLiteral * {
29 const int numBits = 32;
30 return IntegerLiteral::Create(Ctx, llvm::APInt(numBits, Value),
31 Ctx.UnsignedIntTy, {});
34 struct IgnoreParens {
35 Expr *operator()(Expr *E) & { return nullptr; }
36 Expr *operator()(Expr *E) && {
37 if (auto *PE = dyn_cast<ParenExpr>(E)) {
38 return PE->getSubExpr();
40 return E;
45 auto *IntExpr = createIntLiteral(10);
46 ParenExpr *PE =
47 new (Ctx) ParenExpr(SourceLocation{}, SourceLocation{}, IntExpr);
48 EXPECT_EQ(IntExpr, IgnoreExprNodes(PE, IgnoreParens{}));
52 IgnoreParens CB{};
53 auto *IntExpr = createIntLiteral(10);
54 ParenExpr *PE =
55 new (Ctx) ParenExpr(SourceLocation{}, SourceLocation{}, IntExpr);
56 EXPECT_EQ(nullptr, IgnoreExprNodes(PE, CB));