-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-clang Author: Haojian Wu (hokein) ChangesFixes #109442 Full diff: https://github.com/llvm/llvm-project/pull/109653.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da5205087fd821..5ca208de5790f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,9 @@ Attribute Changes in Clang
- Introduced a new attribute ``[[clang::coro_await_elidable_argument]]`` on function parameters
to propagate safe elide context to arguments if such function is also under a safe elide context.
+- 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 {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM.
…L explicit template specialization declarations.
ff56c38
to
ea66fe5
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/6188 Here is the relevant piece of the build log for the reference
|
Fixes #109442