https://github.com/hokein created https://github.com/llvm/llvm-project/pull/109653
Fixes #109442 >From ff56c38c032496277dd31a1c3f158e6eacb9fd7d Mon Sep 17 00:00:00 2001 From: Haojian Wu <hokein...@gmail.com> Date: Mon, 23 Sep 2024 13:50:39 +0200 Subject: [PATCH] [clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to STL explicit template specialization declarations. --- clang/docs/ReleaseNotes.rst | 3 +++ clang/lib/Sema/SemaTemplate.cpp | 1 + .../test/SemaCXX/attr-gsl-owner-pointer-std.cpp | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index da5205087fd821..5ca208de5790f6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -268,6 +268,9 @@ Attribute Changes in Clang - Introduced a new attribute ``[[clang::coro_await_elidable_argument]]`` on function parameters to propagate safe elide context to arguments if such function is also under a safe elide context. +- Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or + ``[[gsl::Pointer]]`` to STL explicit template specialization decls. (#GH109442) + Improvements to Clang's diagnostics ----------------------------------- diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 92274cda15e0b7..99423b01114cc6 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -8631,6 +8631,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization( return SkipBody->Previous; Specialization->setInvalidDecl(Invalid); + inferGslOwnerPointerAttribute(Specialization); return Specialization; } diff --git a/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp b/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp index 352e1e473580a6..8fb4cc7621fedf 100644 --- a/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp +++ b/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp @@ -27,6 +27,11 @@ class vector { static_assert(sizeof(vector<int>), ""); // Force instantiation. static_assert(sizeof(vector<int>::iterator), ""); // Force instantiation. +template <> +class vector<bool> {}; +// CHECK: ClassTemplateSpecializationDecl {{.*}} vector +// CHECK: OwnerAttr {{.*}} + // If std::container::iterator is a using declaration, attributes are inferred // for the underlying class. template <typename T> @@ -173,6 +178,18 @@ class reference_wrapper; class some_unknown_type; // CHECK: CXXRecordDecl {{.*}} some_unknown_type +using size_t = unsigned; +inline constexpr size_t dynamic_extent = -1; +template <typename _Tp, size_t _Extent = dynamic_extent> +class span; +// CHECK: CXXRecordDecl {{.*}} span +// CHECK: PointerAttr {{.*}} + + +template <typename _Tp> +struct span<_Tp, dynamic_extent> {}; +// CHECK: ClassTemplatePartialSpecializationDecl {{.*}} span +// CHECK: PointerAttr {{.*}} } // namespace std namespace user { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits