[clang] [Clang][NFC] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/131346 >From 6ecbeba21b4d9e2309b0468a90387e7c890ce109 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Fri, 14 Mar 2025 17:58:07 +0200 Subject: [PATCH] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency --- clang/lib/Sema/SemaChecking.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e99e30d75df94..9fbde68b3ebe4 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4867,22 +4867,22 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { // current function or method. In C23 mode, if the second argument is an // integer constant expression with value 0, then we don't bother with this // check. - bool SecondArgIsLastNamedArgument = false; + bool SecondArgIsLastNonVariadicArgument = false; const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts(); if (std::optional Val = TheCall->getArg(1)->getIntegerConstantExpr(Context); Val && LangOpts.C23 && *Val == 0) return false; - // These are valid if SecondArgIsLastNamedArgument is false after the next - // block. + // These are valid if SecondArgIsLastNonVariadicArgument is false after the + // next block. QualType Type; SourceLocation ParamLoc; bool IsCRegister = false; if (const DeclRefExpr *DR = dyn_cast(Arg)) { if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) { - SecondArgIsLastNamedArgument = PV == LastParam; + SecondArgIsLastNonVariadicArgument = PV == LastParam; Type = PV->getType(); ParamLoc = PV->getLocation(); @@ -4891,7 +4891,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { } } - if (!SecondArgIsLastNamedArgument) + if (!SecondArgIsLastNonVariadicArgument) Diag(TheCall->getArg(1)->getBeginLoc(), diag::warn_second_arg_of_va_start_not_last_non_variadic_param); else if (IsCRegister || Type->isReferenceType() || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
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 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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 concept LargeArray = +requires (ArrayType my_array) { requires my_array.size() > 5; }; + +struct Big { + constexpr int size() const { return 100; } +}; + +void g() { + static_assert(LargeArray); +} +} + namespace GH128409 { int &ff(); int &x = ff(); // nointerpreter-note {{declared here}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj ready_for_review https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 8ed77e7bb4d26ad5b2f87d65c77e3faa4539502c Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 13:54:49 +0200 Subject: [PATCH] Remove the restriction that local parameters in constraint-expressions can only appear as unevaluated operands --- clang/lib/Sema/SemaExpr.cpp | 11 --- .../expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- 2 files changed, 18 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
@@ -155,6 +155,19 @@ int g() { } } +namespace GH132825 { imdj wrote: Thank you for the feedback. Will do. https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
https://github.com/imdj created https://github.com/llvm/llvm-project/pull/131346 Change the name of the control variable `SecondArgIsLastNamedArgument` to `SecondArgIsLastNonVariadicArgument` for clarity and consistency. Following feedback on earlier PR that was merged: - #131238 >From 3f4932668ba8b8f74136dc297f98f0f9494da90e Mon Sep 17 00:00:00 2001 From: Imad Aldij <69906094+i...@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:34:39 +0200 Subject: [PATCH] [Clang] Rename SecondArgIsLastNamedArgument for clarity Update the variable and description to reflect its meaning and align with the corresponding warning diagnostic message --- clang/lib/Sema/SemaChecking.cpp | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e99e30d75df94..c8e8cb6f4c150 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4867,14 +4867,14 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { // current function or method. In C23 mode, if the second argument is an // integer constant expression with value 0, then we don't bother with this // check. - bool SecondArgIsLastNamedArgument = false; + bool SecondArgIsLastNonVariadicArgument = false; const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts(); if (std::optional Val = TheCall->getArg(1)->getIntegerConstantExpr(Context); Val && LangOpts.C23 && *Val == 0) return false; - // These are valid if SecondArgIsLastNamedArgument is false after the next + // These are valid if SecondArgIsLastNonVariadicArgument is false after the next // block. QualType Type; SourceLocation ParamLoc; @@ -4882,7 +4882,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { if (const DeclRefExpr *DR = dyn_cast(Arg)) { if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) { - SecondArgIsLastNamedArgument = PV == LastParam; + SecondArgIsLastNonVariadicArgument = PV == LastParam; Type = PV->getType(); ParamLoc = PV->getLocation(); @@ -4891,7 +4891,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { } } - if (!SecondArgIsLastNamedArgument) + if (!SecondArgIsLastNonVariadicArgument) Diag(TheCall->getArg(1)->getBeginLoc(), diag::warn_second_arg_of_va_start_not_last_non_variadic_param); else if (IsCRegister || Type->isReferenceType() || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
https://github.com/imdj edited https://github.com/llvm/llvm-project/pull/131346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix inaccurate wording of warn_second_arg_of_va_start_not_last_named_param (PR #131238)
@@ -4893,7 +4893,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { if (!SecondArgIsLastNamedArgument) Diag(TheCall->getArg(1)->getBeginLoc(), - diag::warn_second_arg_of_va_start_not_last_named_param); imdj wrote: What is the recommended action here? Is it worth it to open a new PR? https://github.com/llvm/llvm-project/pull/131238 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
@@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 21 +#if __cplusplus >= 202302L imdj wrote: Shouldn't it follow the status mentioned here https://cplusplus.github.io/CWG/issues/2517.html? or it there a more definitive source? > Status: C++23 https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 7905577616743f5158560a4b337148ef9cd25f1e Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 14:50:55 +0200 Subject: [PATCH 1/8] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression --- clang/lib/Sema/SemaExpr.cpp | 11 --- 1 file changed, 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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; } >From a3b573c1d1f7120c9a1caa7e6fad42a5309679f0 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:04:15 +0200 Subject: [PATCH 2/8] Remove old tests --- .../expr/expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- .../expr/expr.prim/expr.prim.req/simple-requirement.cpp| 7 --- 2 files changed, 14 deletions(-) diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp index 7515f5c62d5ea..0b6d9e147b3d1 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp @@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - namespace access_checks { namespace in_requires_expression { template >From bbd033d24b3a625d448fb9e7267af54a202e41d7 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:05:17 +0200 Subject: [PATCH 3/8] Add test associated with CWG2517 --- clang/test/CXX/drs/cwg25xx.cpp | 20 1 file changed, 20 insertions(+) diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp index d9a7d2bbb2671..bda2cc6e5e965 100644 --- a/clang/test/CXX/drs/cwg25xx.cpp +++ b/clang/test/CXX/drs/cwg25xx.cpp @@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 +#if __cplusplus >= 202302L +template +concept LargeArray = requires (ArrayType my_array) { + requires my_array.size() > 5; +}; + +struct Big { + constexpr int size() const { return 100; } +}; + +struct Small { + constexpr int size() const { return 3; } +}; + +static_assert(LargeArray); +static_assert(!LargeArray); +#endif +} // namespace cwg2517 + namespace cwg2518 { // cwg2518: 17 #if __cplusplus >= 201103L >From 159505e515da00e6006cba1a68766a5522981d8b Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:07:46 +0200 Subject: [PATCH 4/8] Update cxx_dr_status.html --- clang/www/cxx_dr_status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 16a9b26052f87..21fd1c8c965b7 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -14937,7 +14937,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
@@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 21 +#if __cplusplus >= 202302L imdj wrote: Ok, so it's often based on when the issue was first introduced. Thanks for clearing my misunderstanding. https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 7905577616743f5158560a4b337148ef9cd25f1e Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 14:50:55 +0200 Subject: [PATCH 1/6] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression --- clang/lib/Sema/SemaExpr.cpp | 11 --- 1 file changed, 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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; } >From a3b573c1d1f7120c9a1caa7e6fad42a5309679f0 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:04:15 +0200 Subject: [PATCH 2/6] Remove old tests --- .../expr/expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- .../expr/expr.prim/expr.prim.req/simple-requirement.cpp| 7 --- 2 files changed, 14 deletions(-) diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp index 7515f5c62d5ea..0b6d9e147b3d1 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp @@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - namespace access_checks { namespace in_requires_expression { template >From bbd033d24b3a625d448fb9e7267af54a202e41d7 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:05:17 +0200 Subject: [PATCH 3/6] Add test associated with CWG2517 --- clang/test/CXX/drs/cwg25xx.cpp | 20 1 file changed, 20 insertions(+) diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp index d9a7d2bbb2671..bda2cc6e5e965 100644 --- a/clang/test/CXX/drs/cwg25xx.cpp +++ b/clang/test/CXX/drs/cwg25xx.cpp @@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 +#if __cplusplus >= 202302L +template +concept LargeArray = requires (ArrayType my_array) { + requires my_array.size() > 5; +}; + +struct Big { + constexpr int size() const { return 100; } +}; + +struct Small { + constexpr int size() const { return 3; } +}; + +static_assert(LargeArray); +static_assert(!LargeArray); +#endif +} // namespace cwg2517 + namespace cwg2518 { // cwg2518: 17 #if __cplusplus >= 201103L >From 159505e515da00e6006cba1a68766a5522981d8b Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:07:46 +0200 Subject: [PATCH 4/6] Update cxx_dr_status.html --- clang/www/cxx_dr_status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 16a9b26052f87..21fd1c8c965b7 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -14937,7 +14937,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj edited https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj edited https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/131346 >From 6ecbeba21b4d9e2309b0468a90387e7c890ce109 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Fri, 14 Mar 2025 17:58:07 +0200 Subject: [PATCH] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency --- clang/lib/Sema/SemaChecking.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e99e30d75df94..9fbde68b3ebe4 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4867,22 +4867,22 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { // current function or method. In C23 mode, if the second argument is an // integer constant expression with value 0, then we don't bother with this // check. - bool SecondArgIsLastNamedArgument = false; + bool SecondArgIsLastNonVariadicArgument = false; const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts(); if (std::optional Val = TheCall->getArg(1)->getIntegerConstantExpr(Context); Val && LangOpts.C23 && *Val == 0) return false; - // These are valid if SecondArgIsLastNamedArgument is false after the next - // block. + // These are valid if SecondArgIsLastNonVariadicArgument is false after the + // next block. QualType Type; SourceLocation ParamLoc; bool IsCRegister = false; if (const DeclRefExpr *DR = dyn_cast(Arg)) { if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) { - SecondArgIsLastNamedArgument = PV == LastParam; + SecondArgIsLastNonVariadicArgument = PV == LastParam; Type = PV->getType(); ParamLoc = PV->getLocation(); @@ -4891,7 +4891,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { } } - if (!SecondArgIsLastNamedArgument) + if (!SecondArgIsLastNonVariadicArgument) Diag(TheCall->getArg(1)->getBeginLoc(), diag::warn_second_arg_of_va_start_not_last_non_variadic_param); else if (IsCRegister || Type->isReferenceType() || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
imdj wrote: cc: @erichkeane https://github.com/llvm/llvm-project/pull/131346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/131346 >From 3b2f0f906d24b812f1806540f88b0668198dfa42 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Fri, 14 Mar 2025 17:51:34 +0200 Subject: [PATCH] [Clang] Rename SecondArgIsLastNamedArgument for clarity Update the variable and description to reflect its meaning and align with the corresponding warning diagnostic message --- clang/lib/Sema/SemaChecking.cpp | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e99e30d75df94..c8e8cb6f4c150 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4867,14 +4867,14 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { // current function or method. In C23 mode, if the second argument is an // integer constant expression with value 0, then we don't bother with this // check. - bool SecondArgIsLastNamedArgument = false; + bool SecondArgIsLastNonVariadicArgument = false; const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts(); if (std::optional Val = TheCall->getArg(1)->getIntegerConstantExpr(Context); Val && LangOpts.C23 && *Val == 0) return false; - // These are valid if SecondArgIsLastNamedArgument is false after the next + // These are valid if SecondArgIsLastNonVariadicArgument is false after the next // block. QualType Type; SourceLocation ParamLoc; @@ -4882,7 +4882,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { if (const DeclRefExpr *DR = dyn_cast(Arg)) { if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) { - SecondArgIsLastNamedArgument = PV == LastParam; + SecondArgIsLastNonVariadicArgument = PV == LastParam; Type = PV->getType(); ParamLoc = PV->getLocation(); @@ -4891,7 +4891,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { } } - if (!SecondArgIsLastNamedArgument) + if (!SecondArgIsLastNonVariadicArgument) Diag(TheCall->getArg(1)->getBeginLoc(), diag::warn_second_arg_of_va_start_not_last_non_variadic_param); else if (IsCRegister || Type->isReferenceType() || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
imdj wrote: I just did a rebase after the merge of #131166 . Could you take a look please @AaronBallman and see if everything looks good now? https://github.com/llvm/llvm-project/pull/131346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/131346 >From 0b0361fe5f9c15a2682a642584dc6901053ae1cd Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Sat, 15 Mar 2025 21:43:06 +0200 Subject: [PATCH] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency --- clang/lib/Sema/SemaChecking.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 500e7be84f9fa..c6feb35efce85 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4898,15 +4898,15 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { return false; } - // These are valid if SecondArgIsLastNamedArgument is false after the next - // block. + // These are valid if SecondArgIsLastNonVariadicArgument is false after the + // next block. QualType Type; SourceLocation ParamLoc; bool IsCRegister = false; - bool SecondArgIsLastNamedArgument = false; + bool SecondArgIsLastNonVariadicArgument = false; if (const DeclRefExpr *DR = dyn_cast(Arg)) { if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) { - SecondArgIsLastNamedArgument = PV == LastParam; + SecondArgIsLastNonVariadicArgument = PV == LastParam; Type = PV->getType(); ParamLoc = PV->getLocation(); @@ -4915,7 +4915,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) { } } - if (!SecondArgIsLastNamedArgument) + if (!SecondArgIsLastNonVariadicArgument) Diag(TheCall->getArg(1)->getBeginLoc(), diag::warn_second_arg_of_va_start_not_last_non_variadic_param); else if (IsCRegister || Type->isReferenceType() || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 7905577616743f5158560a4b337148ef9cd25f1e Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 14:50:55 +0200 Subject: [PATCH 1/7] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression --- clang/lib/Sema/SemaExpr.cpp | 11 --- 1 file changed, 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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; } >From a3b573c1d1f7120c9a1caa7e6fad42a5309679f0 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:04:15 +0200 Subject: [PATCH 2/7] Remove old tests --- .../expr/expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- .../expr/expr.prim/expr.prim.req/simple-requirement.cpp| 7 --- 2 files changed, 14 deletions(-) diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp index 7515f5c62d5ea..0b6d9e147b3d1 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp @@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - namespace access_checks { namespace in_requires_expression { template >From bbd033d24b3a625d448fb9e7267af54a202e41d7 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:05:17 +0200 Subject: [PATCH 3/7] Add test associated with CWG2517 --- clang/test/CXX/drs/cwg25xx.cpp | 20 1 file changed, 20 insertions(+) diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp index d9a7d2bbb2671..bda2cc6e5e965 100644 --- a/clang/test/CXX/drs/cwg25xx.cpp +++ b/clang/test/CXX/drs/cwg25xx.cpp @@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 +#if __cplusplus >= 202302L +template +concept LargeArray = requires (ArrayType my_array) { + requires my_array.size() > 5; +}; + +struct Big { + constexpr int size() const { return 100; } +}; + +struct Small { + constexpr int size() const { return 3; } +}; + +static_assert(LargeArray); +static_assert(!LargeArray); +#endif +} // namespace cwg2517 + namespace cwg2518 { // cwg2518: 17 #if __cplusplus >= 201103L >From 159505e515da00e6006cba1a68766a5522981d8b Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:07:46 +0200 Subject: [PATCH 4/7] Update cxx_dr_status.html --- clang/www/cxx_dr_status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 16a9b26052f87..21fd1c8c965b7 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -14937,7 +14937,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
@@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 imdj wrote: Thank you, I wasn't sure how this work related to releases. I fixed it. https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 7905577616743f5158560a4b337148ef9cd25f1e Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 14:50:55 +0200 Subject: [PATCH 1/6] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression --- clang/lib/Sema/SemaExpr.cpp | 11 --- 1 file changed, 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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; } >From a3b573c1d1f7120c9a1caa7e6fad42a5309679f0 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:04:15 +0200 Subject: [PATCH 2/6] Remove old tests --- .../expr/expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- .../expr/expr.prim/expr.prim.req/simple-requirement.cpp| 7 --- 2 files changed, 14 deletions(-) diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp index 7515f5c62d5ea..0b6d9e147b3d1 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp @@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - namespace access_checks { namespace in_requires_expression { template >From bbd033d24b3a625d448fb9e7267af54a202e41d7 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:05:17 +0200 Subject: [PATCH 3/6] Add test associated with CWG2517 --- clang/test/CXX/drs/cwg25xx.cpp | 20 1 file changed, 20 insertions(+) diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp index d9a7d2bbb2671..bda2cc6e5e965 100644 --- a/clang/test/CXX/drs/cwg25xx.cpp +++ b/clang/test/CXX/drs/cwg25xx.cpp @@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 +#if __cplusplus >= 202302L +template +concept LargeArray = requires (ArrayType my_array) { + requires my_array.size() > 5; +}; + +struct Big { + constexpr int size() const { return 100; } +}; + +struct Small { + constexpr int size() const { return 3; } +}; + +static_assert(LargeArray); +static_assert(!LargeArray); +#endif +} // namespace cwg2517 + namespace cwg2518 { // cwg2518: 17 #if __cplusplus >= 201103L >From 159505e515da00e6006cba1a68766a5522981d8b Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:07:46 +0200 Subject: [PATCH 4/6] Update cxx_dr_status.html --- clang/www/cxx_dr_status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 16a9b26052f87..21fd1c8c965b7 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -14937,7 +14937,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj converted_to_draft https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj ready_for_review https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 7905577616743f5158560a4b337148ef9cd25f1e Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 14:50:55 +0200 Subject: [PATCH 1/5] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression --- clang/lib/Sema/SemaExpr.cpp | 11 --- 1 file changed, 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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; } >From a3b573c1d1f7120c9a1caa7e6fad42a5309679f0 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:04:15 +0200 Subject: [PATCH 2/5] Remove old tests --- .../expr/expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- .../expr/expr.prim/expr.prim.req/simple-requirement.cpp| 7 --- 2 files changed, 14 deletions(-) diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp index 7515f5c62d5ea..0b6d9e147b3d1 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp @@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - namespace access_checks { namespace in_requires_expression { template >From bbd033d24b3a625d448fb9e7267af54a202e41d7 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:05:17 +0200 Subject: [PATCH 3/5] Add test associated with CWG2517 --- clang/test/CXX/drs/cwg25xx.cpp | 20 1 file changed, 20 insertions(+) diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp index d9a7d2bbb2671..bda2cc6e5e965 100644 --- a/clang/test/CXX/drs/cwg25xx.cpp +++ b/clang/test/CXX/drs/cwg25xx.cpp @@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 +#if __cplusplus >= 202302L +template +concept LargeArray = requires (ArrayType my_array) { + requires my_array.size() > 5; +}; + +struct Big { + constexpr int size() const { return 100; } +}; + +struct Small { + constexpr int size() const { return 3; } +}; + +static_assert(LargeArray); +static_assert(!LargeArray); +#endif +} // namespace cwg2517 + namespace cwg2518 { // cwg2518: 17 #if __cplusplus >= 201103L >From 159505e515da00e6006cba1a68766a5522981d8b Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:07:46 +0200 Subject: [PATCH 4/5] Update cxx_dr_status.html --- clang/www/cxx_dr_status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 16a9b26052f87..21fd1c8c965b7 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -14937,7 +14937,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919 >From 7905577616743f5158560a4b337148ef9cd25f1e Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 14:50:55 +0200 Subject: [PATCH 1/5] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression --- clang/lib/Sema/SemaExpr.cpp | 11 --- 1 file changed, 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 Locs, targetDiag(*Locs.begin(), diag::err_thread_unsupported); } - if (isa(D) && isa(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; } >From a3b573c1d1f7120c9a1caa7e6fad42a5309679f0 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:04:15 +0200 Subject: [PATCH 2/5] Remove old tests --- .../expr/expr.prim/expr.prim.req/nested-requirement.cpp| 7 --- .../expr/expr.prim/expr.prim.req/simple-requirement.cpp| 7 --- 2 files changed, 14 deletions(-) diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp index 763d983d20f61..eaef4441c10f8 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp @@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} } template diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp index 7515f5c62d5ea..0b6d9e147b3d1 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp @@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - namespace access_checks { namespace in_requires_expression { template >From bbd033d24b3a625d448fb9e7267af54a202e41d7 Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:05:17 +0200 Subject: [PATCH 3/5] Add test associated with CWG2517 --- clang/test/CXX/drs/cwg25xx.cpp | 20 1 file changed, 20 insertions(+) diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp index d9a7d2bbb2671..bda2cc6e5e965 100644 --- a/clang/test/CXX/drs/cwg25xx.cpp +++ b/clang/test/CXX/drs/cwg25xx.cpp @@ -32,6 +32,26 @@ enum E2 : S::I { e }; #endif } // namespace cwg2516 +namespace cwg2517 { // cwg2517: 23 +#if __cplusplus >= 202302L +template +concept LargeArray = requires (ArrayType my_array) { + requires my_array.size() > 5; +}; + +struct Big { + constexpr int size() const { return 100; } +}; + +struct Small { + constexpr int size() const { return 3; } +}; + +static_assert(LargeArray); +static_assert(!LargeArray); +#endif +} // namespace cwg2517 + namespace cwg2518 { // cwg2518: 17 #if __cplusplus >= 201103L >From 159505e515da00e6006cba1a68766a5522981d8b Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Tue, 25 Mar 2025 15:07:46 +0200 Subject: [PATCH 4/5] Update cxx_dr_status.html --- clang/www/cxx_dr_status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 16a9b26052f87..21fd1c8c965b7 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -14937,7 +14937,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
@@ -37,13 +37,6 @@ namespace std_example { static_assert(D); template struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} using dc1 = D_check; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} - - template - concept C2 = requires (T a) { - requires sizeof(a) == 4; // OK - requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} -}; - static_assert(C2); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static assertion failed}} imdj wrote: If we keep the tests and only remove the expected comments, this results in: ``` error: 'expected-error' diagnostics seen but not expected: File [...]/nested-requirement.cpp Line 44: substitution into constraint expression resulted in a non-constant expression File [...]/nested-requirement.cpp Line 46: static assertion failed error: 'expected-note' diagnostics seen but not expected: File [...]/nested-requirement.cpp Line 44: while checking the satisfaction of nested requirement requested here File [...]/nested-requirement.cpp Line 44: in instantiation of requirement here File [...]/nested-requirement.cpp Line 44: while checking the satisfaction of nested requirement requested here File [...]/nested-requirement.cpp Line 42: while substituting template arguments into constraint expression here File [...]/nested-requirement.cpp Line 46: while checking the satisfaction of concept 'C2' requested here File [...]/nested-requirement.cpp Line 44: function parameter 'a' with unknown value cannot be used in a constant expression File [...]/nested-requirement.cpp Line 42: declared here File [...]/nested-requirement.cpp Line 46: because 'int' does not satisfy 'C2' ``` Should I keep the tests and update the expected failures instead? https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)
@@ -98,13 +98,6 @@ namespace std_example { using c1c2 = C_check; // expected-error{{constraints not satisfied for class template 'C_check' [with T = int *]}} } -// typeid() of an expression becomes potentially evaluated if the expression is -// of a polymorphic type. -class X { virtual ~X(); }; -constexpr bool b = requires (X &x) { static_cast(nullptr); }; -// expected-error@-1{{constraint variable 'x' cannot be used in an evaluated context}} -// expected-note@-2{{'x' declared here}} - imdj wrote: Here similarly we get: ``` error: 'expected-warning' diagnostics seen but not expected: File [...]/simple-requirement.cpp Line 104: left operand of comma operator has no effect File [...]/simple-requirement.cpp Line 104: variable length arrays in C++ are a Clang extension error: 'expected-note' diagnostics seen but not expected: File [...]/simple-requirement.cpp Line 104: function parameter 'x' with unknown value cannot be used in a constant expression File [...]/simple-requirement.cpp Line 104: declared here ``` https://github.com/llvm/llvm-project/pull/132919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits