| 1 | //== unittests/Sema/GslOwnerPointerInference.cpp - gsl::Owner/Pointer ========// |
| 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 "../ASTMatchers/ASTMatchersTest.h" |
| 10 | #include "clang/ASTMatchers/ASTMatchers.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | namespace clang { |
| 14 | using namespace ast_matchers; |
| 15 | |
| 16 | TEST(OwnerPointer, BothHaveAttributes) { |
| 17 | EXPECT_TRUE(matches("template<class T>" |
| 18 | "class [[gsl::Owner]] C;" |
| 19 | |
| 20 | "template<class T>" |
| 21 | "class [[gsl::Owner]] C {};" |
| 22 | |
| 23 | "C<int> c;" , |
| 24 | classTemplateSpecializationDecl( |
| 25 | hasName("C" ), hasAttr(clang::attr::Owner)))); |
| 26 | } |
| 27 | |
| 28 | TEST(OwnerPointer, ForwardDeclOnly) { |
| 29 | EXPECT_TRUE(matches("template<class T>" |
| 30 | "class [[gsl::Owner]] C;" |
| 31 | |
| 32 | "template<class T>" |
| 33 | "class C {};" |
| 34 | |
| 35 | "C<int> c;" , |
| 36 | classTemplateSpecializationDecl( |
| 37 | hasName("C" ), hasAttr(clang::attr::Owner)))); |
| 38 | } |
| 39 | |
| 40 | TEST(OwnerPointer, LateForwardDeclOnly) { |
| 41 | EXPECT_TRUE(matches("template<class T>" |
| 42 | "class C;" |
| 43 | |
| 44 | "template<class T>" |
| 45 | "class C {};" |
| 46 | |
| 47 | "template<class T>" |
| 48 | "class [[gsl::Owner]] C;" |
| 49 | |
| 50 | "C<int> c;" , |
| 51 | classTemplateSpecializationDecl( |
| 52 | hasName("C" ), hasAttr(clang::attr::Owner)))); |
| 53 | } |
| 54 | |
| 55 | } // namespace clang |
| 56 | |