Skip to content

Commit f8f41bf

Browse files
authored
[clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to the STL template specialization declarations. (#109653)
Fixes #109442
1 parent b0dc7b5 commit f8f41bf

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
@@ -273,6 +273,9 @@ Attribute Changes in Clang
273273
not change the behaviour of the compiler, as this was true for previous
274274
versions.
275275

276+
- Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
277+
``[[gsl::Pointer]]`` to STL explicit template specialization decls. (#GH109442)
278+
276279
Improvements to Clang's diagnostics
277280
-----------------------------------
278281

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)