Movatterモバイル変換


[0]ホーム

URL:


Issue 89 - WG21 CWG Issues
Title
Object lifetime does not account for reference rebinding
Status
tc1
Section
6.8.4 [basic.life]
Submitter
AFNOR

Created on1998-10-27.00:00:00 last changed277 months ago

Messages

msg441 (view)
Date: 2000-10-15.00:00:00

Proposed Resolution (10/00):

Add a new bullet to the list of restrictions in6.8.4 [basic.life] paragraph 7, following the second bullet ("the new object is of the sametype..."):

  • the type of the original object is not const-qualified, and,if a class type, does not contain any non-staticdata member whose type is const-qualified or a reference type, and
msg91 (view)
Date: 2003-04-25.00:00:00
From J16/98-0026 = WG21 N1169, "Proposed Defect Reports on ISO/IEC14882, Programming Languages - C++":
A reference is rebindable. This is surprising and unnatural. This canalso cause subtle optimizer bugs.

Example:

    struct T {        int& ri;        T (int& r) : ri (r) { }    };    void bar (T*);    void foo () {        int i;        T x (i);        x.ri = 3;   // the optimizer understands that this is really i = 3        bar (&x);        x.ri = 4;   // optimizer assumes that this writes to i, but this is incorrect    }    int gi;    void bar (T* p) {        p->~T ();        new (p) T (gi);    }
If we replaceT& withT* const in the example thenundefined behavior result and the optimizer is correct.

Proposal: makeT& equivalent toT* const by extendingthe scope of6.8.4 [basic.life]paragraph9 to references.

(See also J16/99-0005 = WG21 N1182, "Proposed Resolutions for CoreLanguage Issues 6, 14, 20, 40, and 89")

In addition, Lisa Lippincott pointed out the following example:

    void f( const bool * );    void g();    int main() {       const bool *b = new const bool( false );       f(b);       if (*b)          g();    }    void f( const bool *b ) {       new ( const_cast<bool *>(b) ) const bool( true );    }

The proposed wording in the paper would still permit this usage andthus prevent an optimizer from eliminating the call tog().

History
DateUserActionArgs
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2000-11-18 00:00:00adminsetmessages: +msg441
2000-11-18 00:00:00adminsetstatus: ready -> dr
2000-05-21 00:00:00adminsetstatus: drafting -> ready
1998-10-27 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp