Skip to content

[clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to the STL template specialization declarations. #109653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------------------

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8631,6 +8631,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
return SkipBody->Previous;

Specialization->setInvalidDecl(Invalid);
inferGslOwnerPointerAttribute(Specialization);
return Specialization;
}

Expand Down
17 changes: 17 additions & 0 deletions clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 {
Expand Down
Loading