diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8f7772baafcdb1..b47e06cb0c5d68 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -273,6 +273,9 @@ Attribute Changes in Clang not change the behaviour of the compiler, as this was true for previous versions. +- 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), ""); // Force instantiation. static_assert(sizeof(vector::iterator), ""); // Force instantiation. +template <> +class vector {}; +// CHECK: ClassTemplateSpecializationDecl {{.*}} vector +// CHECK: OwnerAttr {{.*}} + // If std::container::iterator is a using declaration, attributes are inferred // for the underlying class. template @@ -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 +class span; +// CHECK: CXXRecordDecl {{.*}} span +// CHECK: PointerAttr {{.*}} + + +template +struct span<_Tp, dynamic_extent> {}; +// CHECK: ClassTemplatePartialSpecializationDecl {{.*}} span +// CHECK: PointerAttr {{.*}} } // namespace std namespace user {