[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
Imad Aldij via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 04:21:33 PDT 2025
https://github.com/imdj created https://github.com/llvm/llvm-project/pull/132919
Remove `[expr.prim.req.nested]` check which restrict that local parameters in constraint-expressions can only appear as unevaluated operands. This change makes the treatment of examples like `requires` expressions and other constant expression contexts uniform, consistent with the adoption of P2280.
References:
- https://cplusplus.github.io/CWG/issues/2517.html
- #132825
>From 0e8e663da86c8fe7007b3967d25081d68457f75a Mon Sep 17 00:00:00 2001
From: Imad Aldij <os at imadij.com>
Date: Tue, 25 Mar 2025 13:06:19 +0200
Subject: [PATCH] [Clang] Implement CWG2517 Useless restriction on use of
parameter in constraint-expression
Remove the restriction that local parameters in constraint-expressions can only appear as unevaluated operands. This change makes the treatment of examples like `requires` expressions and other constant expression contexts uniform, consistent with the adoption of P2280.
---
clang/lib/Sema/SemaExpr.cpp | 11 -----------
clang/test/SemaCXX/constant-expression-p2280r4.cpp | 13 +++++++++++++
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3af6d6c23438f..fa8eeb644c179 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -396,17 +396,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
targetDiag(*Locs.begin(), diag::err_thread_unsupported);
}
- if (isa<ParmVarDecl>(D) && isa<RequiresExprBodyDecl>(D->getDeclContext()) &&
- !isUnevaluatedContext()) {
- // C++ [expr.prim.req.nested] p3
- // A local parameter shall only appear as an unevaluated operand
- // (Clause 8) within the constraint-expression.
- Diag(Loc, diag::err_requires_expr_parameter_referenced_in_evaluated_context)
- << D;
- Diag(D->getLocation(), diag::note_entity_declared_at) << D;
- return true;
- }
-
return false;
}
diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
index f22430a0e88a2..9baedd9c6c263 100644
--- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp
+++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
@@ -155,6 +155,19 @@ int g() {
}
}
+namespace GH132825 {
+template<typename ArrayType> concept LargeArray =
+ requires (ArrayType my_array) { requires my_array.size() > 5; };
+
+struct Big {
+ constexpr int size() const { return 100; }
+};
+
+void g() {
+ static_assert(LargeArray<Big>);
+}
+}
+
namespace GH128409 {
int &ff();
int &x = ff(); // nointerpreter-note {{declared here}}
More information about the cfe-commits
mailing list