0

According to cppref, a constant expression is not bound to be a core constant expression.

My question:

Is there a constant expression that is not a core constant expression?

R Sahu
  • 204,454
  • 14
  • 159
  • 270
xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • 1
    What do you mean by "a `constexpr`"? `constexpr` is a keyword that means two different things, depending on where it is used. – Nicol Bolas Mar 28 '17 at 03:17
  • 1
    Also, where does that website say that there are constant expressions that are not core constant expressions? – Nicol Bolas Mar 28 '17 at 04:20

2 Answers2

4

[expr.const]/5 defines "constant expression" as:

A constant expression is either a glvalue core constant expression that refers to an entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value satisfies the following constraints: [...]

There is no such thing as a constant expression that isn't a core constant expression, and cppreference doesn't claim otherwise.

T.C.
  • 133,968
  • 17
  • 288
  • 421
  • ...which is to say the answer is: no. Note in the quote above (from Section 11 of [expr.const]) that *constant expressions* are defined in terms of *core constant expressions* - i.e. every *constant expression* is a *core constant expression* by definition. – user2023370 Oct 13 '21 at 14:48
  • It is interesting that while that definition comes from Section 11 of [expr.const] ... usages of the term "constant expression" occur throughout [expr.const] - starting at Section 2.2. I wonder if all those usages are specifically "constant expressions" rather than "core constant expressions"...especially as the introductory clause at Section 1 introduces the section topic as "constant expressions" (rather than "core constant expressions"). – user2023370 Oct 13 '21 at 14:51
1

[expr.const] lists a whole series of things that are not core constant expressions. These include signed integer overflow (65536 * 32768 on a 32 bit machine), division by zero, and certain shift operations.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • Is `constexpr int n = 1 / 0;` a `constant expression` but not a `core constant expression`? – xmllmx Mar 28 '17 at 03:45
  • @xmllmx - No, the expression `1/0` is not a core constant expression and therefore is not a constant expression. – mada Sep 17 '22 at 12:18