Skip to content

Commit 0e8e663

Browse files
committed
[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.
1 parent e696f4e commit 0e8e663

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
396396
targetDiag(*Locs.begin(), diag::err_thread_unsupported);
397397
}
398398

399-
if (isa<ParmVarDecl>(D) && isa<RequiresExprBodyDecl>(D->getDeclContext()) &&
400-
!isUnevaluatedContext()) {
401-
// C++ [expr.prim.req.nested] p3
402-
// A local parameter shall only appear as an unevaluated operand
403-
// (Clause 8) within the constraint-expression.
404-
Diag(Loc, diag::err_requires_expr_parameter_referenced_in_evaluated_context)
405-
<< D;
406-
Diag(D->getLocation(), diag::note_entity_declared_at) << D;
407-
return true;
408-
}
409-
410399
return false;
411400
}
412401

clang/test/SemaCXX/constant-expression-p2280r4.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ int g() {
155155
}
156156
}
157157

158+
namespace GH132825 {
159+
template<typename ArrayType> concept LargeArray =
160+
requires (ArrayType my_array) { requires my_array.size() > 5; };
161+
162+
struct Big {
163+
constexpr int size() const { return 100; }
164+
};
165+
166+
void g() {
167+
static_assert(LargeArray<Big>);
168+
}
169+
}
170+
158171
namespace GH128409 {
159172
int &ff();
160173
int &x = ff(); // nointerpreter-note {{declared here}}

0 commit comments

Comments
 (0)