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

46 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[diff.cpp11.expr]
# Annex C (informative) Compatibility [[diff]](./#diff)
## C.5 C++ and ISO C++ 2011 [[diff.cpp11]](diff.cpp11#expr)
### C.5.4 [[expr]](expr "7Expressions"): expressions [diff.cpp11.expr]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L2015)
**Affected subclause:** [[expr.cond]](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[.](#1.sentence-1)
**Rationale:** Formerly mandated conversions ([lvalue-to-rvalue](conv.lval "7.3.2Lvalue-to-rvalue conversion[conv.lval]"),[array-to-pointer](conv.array "7.3.3Array-to-pointer conversion[conv.array]"), and [function-to-pointer](conv.func "7.3.4Function-to-pointer conversion[conv.func]") standard conversions), especially the creation of the temporary due to
lvalue-to-rvalue conversion, were considered gratuitous and surprising[.](#1.sentence-2)
**Effect on original feature:** Valid C++ 2011 code that relies on the conversions may behave differently
in this revision of C++[.](#1.sentence-3)
[*Example [1](#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[.](#1.sentence-4)
In this revision of C++,
it returns 2[.](#1.sentence-5)
sizeof(true ? "" : throw 0)
In C++ 2011, the expression yields sizeof(const char*)[.](#1.sentence-6)
In this
revision of C++, it yields sizeof(const char[1])[.](#1.sentence-7)
— *end example*]