Movatterモバイル変換


[0]ホーム

URL:


Issue 2126 - WG21 CWG Issues
Title
Lifetime-extended temporaries in constant expressions
Status
c++20
Section
7.7 [expr.const]
Submitter
Richard Smith

Created on2015-05-20.00:00:00 last changed62 months ago

Messages

msg6446 (view)
Date: 2019-10-15.00:00:00

Proposed resolution (October, 2019):

Change 7.7 [expr.const] paragraph 3 as follows:

A variable isusable in constant expressions afterits initializing declaration is encountered if it is aconstexpr variable, or it is a constant-initialized variableof reference type or of const-qualified integral orenumeration type. An object or reference isusable inconstant expressions if it is

  • a variable that is usable in constantexpressions, or

  • a template parameter object(13.2 [temp.param]), or

  • a string literal object(5.13.5 [lex.string]), or

  • a temporary object of non-volatile const-qualifiedliteral type whose lifetime is extended(6.8.7 [class.temporary]) to that of a variable that is usablein constant expressions, or

  • a non-mutable subobject or reference member of any of theabove, or.

  • a complete temporary object of non-volatile const-qualifiedintegral or enumeration type that is initialized with aconstant expression.

This resolution also resolvesissue 2439.

msg5649 (view)
Date: 2019-11-15.00:00:00

[Adopted as a DR at the November, 2019 meeting.]

Consider an example like the following:

  typedef const int CI[3];  constexpr CI &ci = CI{11, 22, 33};  static_assert(ci[1] == 22, "");

This is ill-formed because the lifetime of the array temporarydid not start within the current evaluation. Perhaps we shouldtreat all lifetime-extended temporaries of const-qualified literaltype that are initialized by constant expressions as if they areconstexpr objects?

History
DateUserActionArgs
2020-12-15 00:00:00adminsetmessages: +msg6446
2020-12-15 00:00:00adminsetstatus: drafting -> c++20
2015-05-20 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp