Skip to content

Commit

Permalink
[clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to th…
Browse files Browse the repository at this point in the history
…e STL template specialization declarations. (#109653)

Fixes #109442
  • Loading branch information
hokein authored Sep 23, 2024
1 parent b0dc7b5 commit f8f41bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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

0 comments on commit f8f41bf

Please sign in to comment.