Skip to content

Commit ff56c38

Browse files
committed
[clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to STL explicit
template specialization declarations.
1 parent 19ecded commit ff56c38

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ Attribute Changes in Clang
268268
- Introduced a new attribute ``[[clang::coro_await_elidable_argument]]`` on function parameters
269269
to propagate safe elide context to arguments if such function is also under a safe elide context.
270270

271+
- Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
272+
``[[gsl::Pointer]]`` to STL explicit template specialization decls. (#GH109442)
273+
271274
Improvements to Clang's diagnostics
272275
-----------------------------------
273276

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8631,6 +8631,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
86318631
return SkipBody->Previous;
86328632

86338633
Specialization->setInvalidDecl(Invalid);
8634+
inferGslOwnerPointerAttribute(Specialization);
86348635
return Specialization;
86358636
}
86368637

clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class vector {
2727
static_assert(sizeof(vector<int>), ""); // Force instantiation.
2828
static_assert(sizeof(vector<int>::iterator), ""); // Force instantiation.
2929

30+
template <>
31+
class vector<bool> {};
32+
// CHECK: ClassTemplateSpecializationDecl {{.*}} vector
33+
// CHECK: OwnerAttr {{.*}}
34+
3035
// If std::container::iterator is a using declaration, attributes are inferred
3136
// for the underlying class.
3237
template <typename T>
@@ -173,6 +178,18 @@ class reference_wrapper;
173178
class some_unknown_type;
174179
// CHECK: CXXRecordDecl {{.*}} some_unknown_type
175180

181+
using size_t = unsigned;
182+
inline constexpr size_t dynamic_extent = -1;
183+
template <typename _Tp, size_t _Extent = dynamic_extent>
184+
class span;
185+
// CHECK: CXXRecordDecl {{.*}} span
186+
// CHECK: PointerAttr {{.*}}
187+
188+
189+
template <typename _Tp>
190+
struct span<_Tp, dynamic_extent> {};
191+
// CHECK: ClassTemplatePartialSpecializationDecl {{.*}} span
192+
// CHECK: PointerAttr {{.*}}
176193
} // namespace std
177194

178195
namespace user {

0 commit comments

Comments
 (0)