> Date: Mon, 22 Jan 2024 14:33:59 -0500 > From: Marek Polacek <pola...@redhat.com>
> On Mon, Jan 22, 2024 at 06:02:32PM +0100, Hans-Peter Nilsson wrote: > > I don't really know whether this is the right way to treat > > CONVERT_EXPR as below, but... Regtested native > > x86_64-linux-gnu. Ok to commit? > > Thanks for taking a look at this problem. Honestly, it's more like posting a patch is more effective than just opening a PR. ;) And I was curious about that constexpr thing that usually works, but blew up here. > > brgds, H-P > > > > -- >8 -- > > That gcc_unreachable at the default-label seems to be over > > the top. It seems more correct to just say "that's not > > constant" to whatever's not known (to be constant), when > > looking for matches in switch-statements. > > Unfortunately this doesn't seem correct to me; I don't think we > should have gotten that far. The gcc_unreachable was indeed a clue in that direction. > It appears that we lose track of > the reinterpret_cast, which is not allowed in a constant expression: > <http://eel.is/c++draft/expr.const#5.15>. B...b..but clang allows it... (and I have no clue about the finer --or admittedly even coarser-- details of C++) ...and not-my-code, just "porting" it. Seriously though, thanks for the reference. Also, maybe something to consider for -fpermissive, if this changes to a more graceful error path. > cp_convert -> ... -> convert_to_integer_1 gives us a CONVERT_EXPR > but we only set REINTERPRET_CAST_P on NOP_EXPRs: > > expr = cp_convert (type, expr, complain); > if (TREE_CODE (expr) == NOP_EXPR) > /* Mark any nop_expr that created as a reintepret_cast. */ > REINTERPRET_CAST_P (expr) = true; > > so when evaluating baz we get (long unsigned int) &foo, which > passes verify_constant. > > I don't have a good suggestion yet, sorry. Thanks for the review! > > With this patch, the code generated for the (inlined) call to > > ifbar equals that to swbar, except for the comparisons being > > in another order. > > > > gcc/cp: > > PR c++/113545 > > * constexpr.cc (label_matches): Replace call to_unreachable with > > "to gcc_unreachable" Oops! > > return false. > > More like with "break" but that's not important. (Well, *effectively* return false. I'd change to something like "Replace call to gcc_unreachable with arrangement to return false" if this were to go anywhere.) > > gcc/testsuite: > > * g++.dg/expr/pr113545.C: New text. > > "test" Gosh, horrible typos, thanks. brgds, H-P