[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 15 03:13:32 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Zhikai Zeng (Backl1ght)
<details>
<summary>Changes</summary>
fixes https://github.com/llvm/llvm-project/issues/93788 .
---
Full diff: https://github.com/llvm/llvm-project/pull/95651.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1)
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+1-1)
- (modified) clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp (+36)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36efeb8c70cca..3717e573419e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -858,6 +858,7 @@ Bug Fixes to C++ Support
- Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307),
(#GH88081), (#GH89496), (#GH90669) and (#GH91633).
- Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368).
+- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 863cc53c55afa..1fe1fe9d4f833 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2735,7 +2735,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
if (TPLInst.isInvalid())
return nullptr;
TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
- if (!TPL)
+ if (!TPL || Trap.hasErrorOccurred())
TransRetReq.emplace(createSubstDiag(SemaRef, Info,
[&] (llvm::raw_ostream& OS) {
RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
index b7366207882f9..dc0e84280e056 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
@@ -189,3 +189,39 @@ namespace std_example {
template<C5 T> struct C5_check {}; // expected-note{{because 'short' does not satisfy 'C5'}}
using c5 = C5_check<short>; // expected-error{{constraints not satisfied for class template 'C5_check' [with T = short]}}
}
+
+namespace access_checks {
+namespace in_return_type_requirement {
+
+// https://github.com/llvm/llvm-project/issues/93788
+template <typename From, typename To>
+concept is_assignable = requires(From from, To to) {
+ from = to;
+};
+
+template <typename T>
+class trait {
+ public:
+ using public_type = int;
+ private:
+ using private_type = int;
+};
+
+template <typename T>
+concept has_field = requires(T t) {
+ { t.field } -> is_assignable<typename trait<T>::private_type>; // expected-note {{'private_type' is a private member}}
+};
+template <typename T>
+concept has_field2 = requires(T t) {
+ { t.field } -> is_assignable<typename trait<T>::public_type>;
+};
+
+struct A {
+ int field;
+};
+static_assert(has_field<A>); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 'has_field'}}
+static_assert(has_field2<A>);
+
+} // namespace access_checks
+} // namespace in_return_type_requirement
``````````
</details>
https://github.com/llvm/llvm-project/pull/95651
More information about the cfe-commits
mailing list