Title
Internal-linkage constexpr references and ODR requirements
Status
cd4
Section
6.3 [basic.def.odr]
Submitter
James Widman

Created on 2015-03-17.00:00:00 last changed 94 months ago

Messages

Date: 2016-01-15.00:00:00

Proposed resolution (January, 2016):

Change 6.3 [basic.def.odr] bullet 6.2 as follows, dividing the running text into a bulleted list:

...Given such an entity named D defined in more than one translation unit, then

  • each definition of D shall consist of the same sequence of tokens; and

  • in each definition of D, corresponding names, looked up according to 6.5 [basic.lookup], shall refer to an entity defined within the definition of D, or shall refer to the same entity, after overload resolution (12.2 [over.match]) and after matching of partial template specialization (13.10.4 [temp.over]), except that a name can refer to

    • a non-volatile const object with internal or no linkage if the object

      • has the same literal type in all definitions of D, and

      • the object is initialized with a constant expression (7.7 [expr.const]), and

      • the object is not odr-used, and

      • the object has the same value in all definitions of D,

      or

    • a reference with internal or no linkage initialized with a constant expression such that the reference refers to the same entity in all definitions of D;

    and

  • in each definition of D, corresponding entities...

Date: 2016-02-15.00:00:00

[Adopted at the February, 2016 meeting.]

In an example like:

  extern int i;
  namespace {
    constexpr int& r = i;
  }
  inline int f() { return r; }

use of f() in multiple translation units results in an ODR violation because of use of the internal-linkage reference r. It would be helpful if 6.3 [basic.def.odr] paragraph 6 could be amended to “look through” a constexpr reference in determining whether an inline function violates the ODR or not.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: tentatively ready -> cd4
2016-02-15 00:00:00adminsetmessages: + msg5692
2016-02-15 00:00:00adminsetstatus: drafting -> tentatively ready
2015-03-17 00:00:00admincreate