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

Created on 2014-06-22.00:00:00 last changed 95 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 7.7 [expr.const] bullet 2.5 as follows:

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

  2. Add the following at the end of 7.7 [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 Clause 16 [library] through Clause 32 [thread] of this International Standard, it is unspecified whether e is a core constant expression.
Date: 2022-02-18.07:47:23

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

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

  • ...

  • an operation that would have undefined behavior [Note: including, for example, signed integer overflow (Clause 7 [expr]), certain pointer arithmetic (7.6.6 [expr.add]), division by zero (7.6.5 [expr.mul]), or certain shift operations (7.6.7 [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