Files
2025-10-25 03:02:53 +03:00

1.6 KiB

[diff.cpp11.expr]

Annex C (informative) Compatibility [diff]

C.5 C++ and ISO C++ 2011 [diff.cpp11]

C.5.4 [expr]: expressions [diff.cpp11.expr]

1

#

Affected subclause: [expr.cond]

Change: A conditional expression with a throw expression as its second or third operand keeps the type and value category of the other operand.

Rationale: Formerly mandated conversions (lvalue-to-rvalue,array-to-pointer, and function-to-pointer standard conversions), especially the creation of the temporary due to lvalue-to-rvalue conversion, were considered gratuitous and surprising.

Effect on original feature: Valid C++ 2011 code that relies on the conversions may behave differently in this revision of C++.

[Example 1: struct S {int x = 1; void mf() { x = 2; }};int f(bool cond) { S s; (cond ? s : throw 0).mf(); return s.x;}

In C++ 2011, f(true) returns 1.

In this revision of C++, it returns 2.

sizeof(true ? "" : throw 0)

In C++ 2011, the expression yields sizeof(const char*).

In this revision of C++, it yields sizeof(const char[1]).

— end example]