Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


2242. ODR violation with constant initialization possibly omitted

Section:6.3  [basic.def.odr]    Status:C++23    Submitter:Hubert Tong    Date:2016-03-05

P2720R0 comment US 5-033

[Accepted as a DR at the November, 2022 meeting.]

Consider the following example:

  // tu1.cpp  extern const int a = 1;  inline auto f() {    static const int b = a;    struct A { auto operator()() { return &b; } } a;    return a;  }  // tu2.cpp  extern const int a;  inline auto f() {    static const int b = a;    struct A { auto operator()() { return &b; } } a;    return a;  }  int main() {    return *decltype(f())()();  }

Here,b may or may not have constant initialization.This example should be an ODR violation.

(Split off fromissue 2123.)

Proposed resolution (approved by CWG 2022-11-11):

Insert after 6.3 [basic.def.odr] bullet 14.7 as follows:




[8]ページ先頭

©2009-2026 Movatter.jp