https://github.com/ShashwatAgrawal20 created 
https://github.com/llvm/llvm-project/pull/246811

## 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).

>From 6d2b2aadb324cdbfc1b782c73a637394fe630fe3 Mon Sep 17 00:00:00 2001
From: Shashwat Agrawal <[email protected]>
Date: Sat, 28 Nov 2026 12:17:19 +0530
Subject: [PATCH] [clang][Sema] Fix access checking in nested concept-id
 substitution

Access-control failures are diagnosed as SFINAE and recorded on the
active SFINAETrap, but SubstTemplateArgumentsInParameterMapping still
returns success. In SubstitutionInTemplateArguments, this caused private
member access in a nested concept-id argument to be ignored, making the
enclosing concept incorrectly satisfied.

Check the trap after parameter mapping substitution and consume the
SFINAE diagnostic, matching the existing atomic-constraint path.

Fixes #246008

Signed-off-by: Shashwat Agrawal <[email protected]>
---
 clang/lib/Sema/SemaConcept.cpp                |  7 ++++-
 .../SemaCXX/concept-access-in-concept-id.cpp  | 26 +++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/concept-access-in-concept-id.cpp

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>);

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

Reply via email to