GslOwnerPointerInference.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "../ASTMatchers/ASTMatchersTest.h"
  9. #include "clang/ASTMatchers/ASTMatchers.h"
  10. #include "gtest/gtest.h"
  11. namespace clang {
  12. using namespace ast_matchers;
  13. TEST(OwnerPointer, BothHaveAttributes) {
  14. EXPECT_TRUE(matches("template<class T>"
  15. "class [[gsl::Owner]] C;"
  16. "template<class T>"
  17. "class [[gsl::Owner]] C {};"
  18. "C<int> c;",
  19. classTemplateSpecializationDecl(
  20. hasName("C"), hasAttr(clang::attr::Owner))));
  21. }
  22. TEST(OwnerPointer, ForwardDeclOnly) {
  23. EXPECT_TRUE(matches("template<class T>"
  24. "class [[gsl::Owner]] C;"
  25. "template<class T>"
  26. "class C {};"
  27. "C<int> c;",
  28. classTemplateSpecializationDecl(
  29. hasName("C"), hasAttr(clang::attr::Owner))));
  30. }
  31. TEST(OwnerPointer, LateForwardDeclOnly) {
  32. EXPECT_TRUE(matches("template<class T>"
  33. "class C;"
  34. "template<class T>"
  35. "class C {};"
  36. "template<class T>"
  37. "class [[gsl::Owner]] C;"
  38. "C<int> c;",
  39. classTemplateSpecializationDecl(
  40. hasName("C"), hasAttr(clang::attr::Owner))));
  41. }
  42. } // namespace clang