2019-09-06 16:56:30 +08:00
|
|
|
//== unittests/Sema/GslOwnerPointerInference.cpp - gsl::Owner/Pointer ========//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ASTMatchers/ASTMatchersTest.h"
|
|
|
|
#include "clang/ASTMatchers/ASTMatchers.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
using namespace ast_matchers;
|
|
|
|
|
|
|
|
TEST(OwnerPointer, BothHaveAttributes) {
|
2019-09-07 03:15:02 +08:00
|
|
|
EXPECT_TRUE(matches("template<class T>"
|
|
|
|
"class [[gsl::Owner]] C;"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"template<class T>"
|
|
|
|
"class [[gsl::Owner]] C {};"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"C<int> c;",
|
|
|
|
classTemplateSpecializationDecl(
|
|
|
|
hasName("C"), hasAttr(clang::attr::Owner))));
|
2019-09-06 16:56:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(OwnerPointer, ForwardDeclOnly) {
|
2019-09-07 03:15:02 +08:00
|
|
|
EXPECT_TRUE(matches("template<class T>"
|
|
|
|
"class [[gsl::Owner]] C;"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"template<class T>"
|
|
|
|
"class C {};"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"C<int> c;",
|
|
|
|
classTemplateSpecializationDecl(
|
|
|
|
hasName("C"), hasAttr(clang::attr::Owner))));
|
2019-09-06 16:56:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(OwnerPointer, LateForwardDeclOnly) {
|
2019-09-07 03:15:02 +08:00
|
|
|
EXPECT_TRUE(matches("template<class T>"
|
|
|
|
"class C;"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"template<class T>"
|
|
|
|
"class C {};"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"template<class T>"
|
|
|
|
"class [[gsl::Owner]] C;"
|
2019-09-06 16:56:30 +08:00
|
|
|
|
2019-09-07 03:15:02 +08:00
|
|
|
"C<int> c;",
|
|
|
|
classTemplateSpecializationDecl(
|
|
|
|
hasName("C"), hasAttr(clang::attr::Owner))));
|
2019-09-06 16:56:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace clang
|