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

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #4)
> This one is valid, but before your r12-7264 was incorrectly rejected because
> 8 * baz (0) etc. is wrapped in NON_DEPENDENT_EXPR,
> potential_constant_expression_1 recursed on the NON_DEPENDENT_EXPR operand,
> found it is ok but cxx_eval_constant_expression
> rejected the NON_DEPENDENT_EXPR.

Makes sense, similar to the #2 case in comment #5.

> Bet for the build_over_call
> processing_template_decl immediate_invocation_p code we need to punt
> silently if there is something we can't handle but fail loudly if we can
> handle everything but it is clearly always not a constant expression. 
> potential_constant_expression_1 isn't 100% accurate, there are cases where
> it gets stuff through.

IIUC as long as NON_DEPENDENT_EXPR doesn't appear inside a non-dependent
consteval call then we'll currently correctly accept/reject it ahead of time,
e.g.:

consteval int foo(int x) { return x; }

template<class>
void bar(int x)
{
  constexpr int y = 0;
  foo(x);     // error: 'x' is not a constant expression
  foo(y);     // OK
  foo(x * 1); // no (ahead of time) error due to NON_DEPENDENT_EXPR
}

Reply via email to