[clang] f8f41bf - [clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to the STL template specialization declarations. (#109653)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 23 05:59:34 PDT 2024
Author: Haojian Wu
Date: 2024-09-23T14:59:30+02:00
New Revision: f8f41bf92c92ebc9b113a2a573d12880b86d5af3
URL: https://github.com/llvm/llvm-project/commit/f8f41bf92c92ebc9b113a2a573d12880b86d5af3
DIFF: https://github.com/llvm/llvm-project/commit/f8f41bf92c92ebc9b113a2a573d12880b86d5af3.diff
LOG: [clang] Apply the [[gsl::Owner]] or [[gsl::Pointer]] attributes to the STL template specialization declarations. (#109653)
Fixes #109442
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
Removed:
################################################################################
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<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>
@@ -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 {
More information about the cfe-commits
mailing list