Title
Constant expressions and library undefined behavior
Status
cd4
Section
8.20 [expr.const]
Submitter
Daniel Krügler

Created on 2014-06-22.00:00:00 last changed 40 months ago

Messages

Date: 2015-05-15.00:00:00

[Moved to DR at the May, 2015 meeting.]

Date: 2015-04-15.00:00:00

Proposed resolution (April, 2015):

  1. Change 8.20 [expr.const] bullet 2.5 as follows:

    • an operation that would have undefined behavior as specified in Clauses 4 [intro] through 19 [cpp] of this International Standard [Note: including, for example, signed integer overflow (Clause 8 [expr]), certain pointer arithmetic (8.7 [expr.add]), division by zero (8.6 [expr.mul]), or certain shift operations (8.8 [expr.shift]) —end note];

  2. Add the following at the end of 8.20 [expr.const] paragraph 2:

  3. If e satisfies the constraints of a core constant expression, but evaluation of e would evaluate an operation that has undefined behavior as specified in Clauses 20 [library] through 33 [thread] of this International Standard, it is unspecified whether e is a core constant expression.
Date: 2014-06-22.00:00:00

According to bullet 2.5 of 8.20 [expr.const],

A conditional-expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine (4.6 [intro.execution]), would evaluate one of the following expressions:

  • ...

  • an operation that would have undefined behavior [Note: including, for example, signed integer overflow (Clause 8 [expr]), certain pointer arithmetic (8.7 [expr.add]), division by zero (8.6 [expr.mul]), or certain shift operations (8.8 [expr.shift]) —end note];

  • ...

The definition of “operation” is unclear. In particular, is it intended to include use of library components that are specified to produce undefined behavior, such as use of the offsetof macro when applied to a non-standard-layout class?

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-11-10 00:00:00adminsetstatus: dr -> drwp
2015-05-25 00:00:00adminsetmessages: + msg6049
2015-05-25 00:00:00adminsetstatus: tentatively ready -> dr
2015-04-13 00:00:00adminsetmessages: + msg5311
2015-04-13 00:00:00adminsetstatus: drafting -> tentatively ready
2014-06-22 00:00:00admincreate