1 //===- unittests/Analysis/CFGTest.cpp - CFG tests -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/ASTMatchers/ASTMatchFinder.h"
11 #include "clang/Analysis/CFG.h"
12 #include "clang/Tooling/Tooling.h"
13 #include "gtest/gtest.h"
21 // Constructing a CFG for a range-based for over a dependent type fails (but
23 TEST(CFG, RangeBasedForOverDependentType) {
24 const char *Code = "class Foo;\n"
25 "template <typename T>\n"
26 "void f(const T &Range) {\n"
27 " for (const Foo *TheFoo : Range) {\n"
31 class CFGCallback : public ast_matchers::MatchFinder::MatchCallback {
33 bool SawFunctionBody = false;
35 void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
36 const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func");
37 Stmt *Body = Func->getBody();
40 SawFunctionBody = true;
41 std::unique_ptr<CFG> cfg =
42 CFG::buildCFG(nullptr, Body, Result.Context, CFG::BuildOptions());
43 EXPECT_EQ(nullptr, cfg);
47 ast_matchers::MatchFinder Finder;
48 Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
49 std::unique_ptr<tooling::FrontendActionFactory> Factory(
50 tooling::newFrontendActionFactory(&Finder));
51 std::vector<std::string> Args = {"-std=c++11", "-fno-delayed-template-parsing"};
52 ASSERT_TRUE(tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args));
53 EXPECT_TRUE(Callback.SawFunctionBody);
57 } // namespace analysis