1 //===- unittests/AST/DeclBaseTest.cpp --- Declaration tests----------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Unit tests for Decl class in the AST.
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/DeclBase.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/Type.h"
17 #include "clang/ASTMatchers/ASTMatchFinder.h"
18 #include "clang/ASTMatchers/ASTMatchers.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Tooling/Tooling.h"
21 #include "gtest/gtest.h"
23 using ::clang::BindingDecl
;
24 using ::clang::ast_matchers::bindingDecl
;
25 using ::clang::ast_matchers::hasName
;
26 using ::clang::ast_matchers::match
;
27 using ::clang::ast_matchers::selectFirst
;
29 TEST(DeclGetFunctionType
, BindingDecl
) {
30 llvm::StringRef Code
= R
"cpp(
31 template <typename A, typename B>
38 Pair<void (*)(int *), bool> P;
39 auto [FunctionPointer, B] = P;
45 clang::tooling::buildASTFromCodeWithArgs(Code
, /*Args=*/{"-std=c++20"});
46 clang::ASTContext
&Ctx
= AST
->getASTContext();
48 auto *BD
= selectFirst
<clang::BindingDecl
>(
50 match(bindingDecl(hasName("FunctionPointer")).bind("FunctionPointer"),
52 ASSERT_NE(BD
, nullptr);
54 EXPECT_NE(BD
->getFunctionType(), nullptr);
56 // Emulate a call before the BindingDecl has a bound type.
57 const_cast<clang::BindingDecl
*>(BD
)->setBinding(clang::QualType(), nullptr);
58 EXPECT_EQ(BD
->getFunctionType(), nullptr);