[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-22 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght closed 
https://github.com/llvm/llvm-project/pull/95651
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-22 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/95651

>From 64ee10bf71d79c97f45779dbbd9f74e85a5676ee Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 15 Jun 2024 16:56:00 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  2 +-
 .../expr.prim.req/compound-requirement.cpp| 36 +++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac0fa0141b47..9c8f8c4a4fbaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -914,6 +914,7 @@ Bug Fixes to C++ Support
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
+- 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 struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // 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 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-21 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/95651

>From 1c283900fc4bc984ebd917ead6ddd8c5d0364d80 Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 15 Jun 2024 16:56:00 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  2 +-
 .../expr.prim.req/compound-requirement.cpp| 36 +++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac0fa0141b47..9c8f8c4a4fbaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -914,6 +914,7 @@ Bug Fixes to C++ Support
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
+- 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 struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // 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 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-17 Thread via cfe-commits

https://github.com/Sirraide approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/95651
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-16 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/95651

>From 49f0d1aff888b2a96ed3a19d8d2e30d367caf14f Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 15 Jun 2024 16:56:00 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  2 +-
 .../expr.prim.req/compound-requirement.cpp| 36 +++
 3 files changed, 38 insertions(+), 1 deletion(-)

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 struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // 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 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zhikai Zeng (Backl1ght)


Changes

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 struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // 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 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement

``




https://github.com/llvm/llvm-project/pull/95651
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-15 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght created 
https://github.com/llvm/llvm-project/pull/95651

fixes https://github.com/llvm/llvm-project/issues/93788 .

>From 7911a757d6b97a12baf465d0fe1a9442ca2ee76b Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 15 Jun 2024 16:56:00 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  2 +-
 .../expr.prim.req/compound-requirement.cpp| 36 +++
 3 files changed, 38 insertions(+), 1 deletion(-)

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 struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // 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 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits