On Thu, Nov 17, 2022 at 07:28:56PM -0500, Jason Merrill wrote: > On 11/17/22 15:42, Jakub Jelinek wrote: > > On Thu, Nov 17, 2022 at 07:42:40PM +0100, Jakub Jelinek via Gcc-patches wrote: > > > I thought for older C++ this is to catch > > > void > > > foo () > > > { > > > constexpr int a = ({ static constexpr int b = 2; b; }); > > > } > > > and for C++23 the only 3 spots that diagnose those. > > > But perhaps for C++20 or older we can check if the var has a context > > > of a constexpr function (then assume cp_finish_decl errored or pedwarned > > > already) and only error or pedwarn otherwise. > > We could, but I wouldn't bother to enforce this specially for > statement-expressions, which are already an extension. Ok. > OTOH, we should test that static constexpr is handled properly for lambdas, > i.e. this should still fail: > > constexpr int q = [](int i) > { static constexpr int x = 42; return x+i; }(24); I guess that is related on how to handle the lambda-generic-func1.C constexpr-lambda16.C FAILs. Attached are 3 patches, one is just an updated version of the previous patch with simplified constexpr.cc (and fixed the function comment Marek talked about), this one will accept the statement expression case with decl_constant_var_p static in it, and passes GXX_TESTSUITE_STDS=98,11,14,17,20,2b make check-g++ \ RUNTESTFLAGS="--target_board=unix\{-m32,-m64\} dg.exp='constexpr-nonlit* feat-cxx2b* stmtexpr19.C stmtexpr25.C lambda-generic-func1.C constexpr-lambda16.C'" except for: +FAIL: g++.dg/cpp1y/lambda-generic-func1.C -std=c++17 (test for excess errors) +FAIL: g++.dg/cpp1y/lambda-generic-func1.C -std=c++20 (test for excess errors) +FAIL: g++.dg/cpp1z/constexpr-lambda16.C -std=c++17 (test for excess errors) +FAIL: g++.dg/cpp1z/constexpr-lambda16.C -std=c++20 (test for excess errors) plus the testcase above needs to be dealt with if we want to pedwarn on it for older C++. The third one is if we just want something for C++23 and don't want to touch C++20 and older at all (that one doesn't regress anything), the second one similarly but will no longer reject the statement expression cases for C++11 .. 20. Jakub