llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Shashwat Agrawal (ShashwatAgrawal20)

<details>
<summary>Changes</summary>

## Summary

fixes #<!-- -->246008 

Access-control failures during concept satisfaction are diagnosed as SFINAE and 
recorded on the active `SFINAETrap`, but
`Sema::SubstTemplateArgumentsInParameterMapping` can still return success. In 
`ConstraintSatisfactionChecker::SubstitutionInTemplateArguments`, the trap was 
only checked when substitution returned failure. As a result, a private-member 
access used in a nested concept-id argument could be ignored, and the enclosing 
concept could be incorrectly satisfied.

Check `Trap.hasErrorOccurred()` after parameter-mapping substitution and 
consume the SFINAE diagnostic, matching the existing atomic-constraint handling.

This regressed in Clang 22 after constraint normalization (#<!-- -->161671).

---
Full diff: https://github.com/llvm/llvm-project/pull/246811.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaConcept.cpp (+6-1) 
- (added) clang/test/SemaCXX/concept-access-in-concept-id.cpp (+26) 


``````````diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 72d2ad4a782e20..86538f484b5f7d 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -812,7 +812,12 @@ 
ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
   // mappings to preserve the outer depths.
   if (S.SubstTemplateArgumentsInParameterMapping(
           Constraint.getParameterMapping(), Constraint.getBeginLoc(), MLTAL,
-          SubstArgs)) {
+          SubstArgs) ||
+      Trap.hasErrorOccurred()) {
+    // Access-control failures are diagnosed as SFINAE, so they don't make
+    // SubstTemplateArgumentsInParameterMapping return true. Check the trap
+    // as well, otherwise the constraint is incorrectly treated as satisfied.
+    // See https://github.com/llvm/llvm-project/issues/246008.
     Satisfaction.IsSatisfied = false;
     if (Trap.hasErrorOccurred())
       consumeSFINAEFailure(Info, Satisfaction);
diff --git a/clang/test/SemaCXX/concept-access-in-concept-id.cpp 
b/clang/test/SemaCXX/concept-access-in-concept-id.cpp
new file mode 100644
index 00000000000000..4e8f2e40955be8
--- /dev/null
+++ b/clang/test/SemaCXX/concept-access-in-concept-id.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s
+
+template <class T, class U> concept same_as = __is_same(T, U);
+template <class T> T &&declval();
+
+template <class T>
+concept has_int_x = same_as<decltype(declval<T>().x), int>;
+
+template <class T>
+using x_t = decltype(declval<T>().x);
+
+template <class T>
+concept has_int_x_via_alias = same_as<x_t<T>, int>;
+
+class A {
+  int x;
+};
+class B {
+public:
+  int x;
+};
+
+static_assert(!has_int_x<A>);
+static_assert(has_int_x<B>);
+static_assert(!has_int_x_via_alias<A>);
+static_assert(has_int_x_via_alias<B>);

``````````

</details>


https://github.com/llvm/llvm-project/pull/246811
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to