https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127478

            Bug ID: 127478
           Summary: [reflection] missing "consteval-only value" error for
                    init of auto var
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

In

```
using info = decltype(^^int);
consteval auto f () { return ^^int; }
consteval auto g () { return info{}; }

void fn1 () { bool b = f () != info{}; }                // { dg-error
"consteval-only value" }
void fn2 () { bool b = g () != info{}; }
void fn3 () { bool b = ^^int != info{}; }               // { dg-error
"consteval-only value" }
void fn4 () { bool b = info{} != info{}; }
constexpr void fn5 () { bool b = f () != info{}; }      // { dg-error
"consteval-only value" }
constexpr void fn6 () { bool b = g () != info{}; }
constexpr void fn7 () { bool b = ^^int != info{}; }     // { dg-error
"consteval-only value" }
constexpr void fn8 () { bool b = info{} != info{}; }
```

we don't give the error for f1, because of:

  /* Don't fold initializers of automatic variables in constexpr functions,
     that might fold away something that needs to be diagnosed at constexpr
     evaluation time.  */
  if (!current_function_decl
      || !maybe_constexpr_fn (current_function_decl)
      || TREE_STATIC (decl))
    value = cp_fully_fold_init (value);

folds the initializer to 1.  We also check the unfolded version but
check_out_of_consteval_use doesn't evaluate a CALL_EXPR so it won't see what it
evaluates to.

Reply via email to