Unclear definition of “potential constant expression”
7.7 [expr.const]

Created on 2010-08-02.00:00:00 last changed 96 months ago


Date: 2010-11-15.00:00:00

[Voted into the WP at the November, 2010 meeting as paper N3218.]

Date: 2010-08-02.00:00:00
N3092 comment DE 8

In the definition of “potential constant expression” in 7.7 [expr.const] paragraph 6, it is unclear how “arbitrary” the substitution of the function parameters is. Does it mean “there exists a value for which the result is a constant expression” or does it mean “for all possible values, the result needs to be a constant expression?” Example:

    constexpr int f(int x){ return x + 1; }

is a constant expression under the first interpretation, but not under the second (because overflow occurs for x == INT_MAX, cf 7.7 [expr.const] paragraph 2 bullet 5). The answer also affects expressions such as:

    constexpr int f2(bool v) { return v ? throw 0 : 0; }
    constexpr int f3(bool v) { return v && (throw 0, 0); }

See also issue 1129.

Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetstatus: dr -> fdis
2010-11-29 00:00:00adminsetstatus: drafting -> dr
2010-10-18 00:00:00adminsetstatus: ready -> drafting
2010-08-23 00:00:00adminsetmessages: + msg2768
2010-08-02 00:00:00admincreate