Movatterモバイル変換


[0]ホーム

URL:


Issue 2083 - WG21 CWG Issues
Title
Incorrect cases of odr-use
Status
cd5
Section
6.3 [basic.def.odr]
Submitter
Hubert Tong

Created on2015-02-11.00:00:00 last changed62 months ago

Messages

msg6347 (view)
Date: 2019-01-15.00:00:00

Proposed resolution (January, 2019):

  1. Change 6.3 [basic.def.odr] bullet 2.4 as follows:

  2. An expression ispotentially evaluated unless itis an unevaluated operand (7.2 [expr.prop]) or asubexpression thereof. The set ofpotential resultsof an expressione is defined as follows:

    • ...

    • Ife is a pointer-to-member expression(7.6.4 [expr.mptr.oper])whose second operand is aconstant expression, the set contains the potential resultsof the object expression.

    • ...

    • Otherwise, the set is empty.

  3. Change 6.3 [basic.def.odr] paragraph 4, converting therunning text into bullets, as follows:

  4. A variablex whose name appears as apotentially-evaluated expressionex is odr-usedbyex unlessapplying the lvalue-to-rvalueconversion (7.3.2 [conv.lval]) tox yieldsa constant expression (7.7 [expr.const]) that doesnot invoke a function other than a trivial special memberfunction (11.4.4 [special]) and, ifx isan object,

    • x is a reference that is usable inconstant expressions (7.7 [expr.const]), or

    • x is a variable of non-reference typethat is usable in constant expressions and has no mutablesubobjects, andex is an elementof the set of potential results of anexpressione, where eitherofnon-volatile-qualified non-class type to which thelvalue-to-rvalue conversion (7.3.2 [conv.lval]) isappliedtoe, ore is

    • x is a variable of non-reference type, ande is an element of the set of potential results ofa discarded-value expression (7.2 [expr.prop])to which the lvalue-to-rvalue conversion is notapplied.

    This resolution also resolves issues2103and2170.

msg5539 (view)
Date: 2019-02-15.00:00:00

[Accepted as a DR at the February, 2019 meeting.]

The resolution ofissue 1741 was notintended to cause odr-use to occur in cases where it did not do sopreviously. However, in an example like

  extern int globx;  int main() {    const int &x = globx;    struct A {     const int *foo() {       return &x;     }    } a;    return *a.foo();  }

x satisfies the requirements for appearing in aconstant expression, but applying the lvalue-to-rvalueconverstion tox does not yield a constant expression.Similarly,

  struct A {    int q;    constexpr A(int q) : q(q) { }    constexpr A(const A &a) : q(a.q * 2) { }  };  int main(void) {    constexpr A a(42);    constexpr int aq = a.q;    struct Q {     int foo() { return a.q; }    } q;    return q.foo();  }

a satisfies the requirements for appearing in a constantexpression, but applying the lvalue-to-rvalue conversion toainvokes a non-trivial function.

History
DateUserActionArgs
2020-12-15 00:00:00adminsetmessages: +msg6347
2020-12-15 00:00:00adminsetstatus: drafting -> cd5
2017-02-06 00:00:00adminsetstatus: open -> drafting
2015-02-11 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp