1//===- unittest/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp -===//
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#include "TestVisitor.h"
10#include <string>
11
12using namespace clang;
13
14namespace {
15
16// Check to ensure that bitfield initializers are visited.
17class BitfieldInitializerVisitor : public ExpectedLocationVisitor {
18public:
19 bool VisitIntegerLiteral(IntegerLiteral *IL) override {
20 Match(Name: std::to_string(IL->getValue().getSExtValue()), Location: IL->getLocation());
21 return true;
22 }
23};
24
25TEST(RecursiveASTVisitor, BitfieldInitializerIsVisited) {
26 BitfieldInitializerVisitor Visitor;
27 Visitor.ExpectMatch("123", 2, 15);
28 EXPECT_TRUE(Visitor.runOver("struct S {\n"
29 " int x : 8 = 123;\n"
30 "};\n"));
31}
32
33} // end anonymous namespace
34

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp