Annex C (informative) Compatibility [diff] (original) (raw)
C.5 C++ and ISO C++ 2011 [diff.cpp11]
C.5.1 General [diff.cpp11.general]
Subclause [diff.cpp11] lists the differences between C++ and ISO C++ 2011, in addition to those listed above, by the chapters of this document.
C.5.2 [lex]: lexical conventions [diff.cpp11.lex]
Affected subclause: [lex.ppnumber]
Change: pp-number can contain one or more single quotes.
Rationale: Necessary to enable single quotes as digit separators.
Effect on original feature: Valid C++ 2011 code may fail to compile or may change meaning in this revision of C++.
For example, the following code is valid both in C++ 2011 and in this revision of C++, but the macro invocation produces different outcomes because the single quotes delimit a character-literal in C++ 2011, whereas they are digit separators in this revision of C++.
[Example 1: #define M(x, ...) __VA_ARGS__int x[2] = { M(1'2,3'4, 5) }; — _end example_]
C.5.3 [basic]: basics [diff.cpp11.basic]
Affected subclause: [basic.stc.dynamic.deallocation]
Change: New usual (non-placement) deallocator.
Rationale: Required for sized deallocation.
Effect on original feature: Valid C++ 2011 code can declare a global placement allocation function and deallocation function as follows:void* operator new(std::size_t, std::size_t);void operator delete(void*, std::size_t) noexcept;
In this revision of C++, however, the declaration of operator deletemight match a predefined usual (non-placement)operator delete ([basic.stc.dynamic]).
If so, the program is ill-formed, as it was for class member allocation functions and deallocation functions ([expr.new]).
C.5.4 [expr]: expressions [diff.cpp11.expr]
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-pointerstandard 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_]
C.5.5 [dcl]: declarations [diff.cpp11.dcl.dcl]
Affected subclause: [dcl.constexpr]
Change: constexpr non-static member functions are not implicitlyconst member functions.
Rationale: Necessary to allow constexpr member functions to mutate the object.
Effect on original feature: Valid C++ 2011 code may fail to compile in this revision of C++.
[Example 1: struct S { constexpr const int &f();int &f();};
This code is valid in C++ 2011 but invalid in this revision of C++ because it declares the same member function twice with different return types.
— _end example_]
Affected subclause: [dcl.init.aggr]
Change: Classes with default member initializers can be aggregates.
Rationale: Necessary to allow default member initializers to be used by aggregate initialization.
Effect on original feature: Valid C++ 2011 code may fail to compile or may change meaning in this revision of C++.
[Example 2: struct S { int m = 1;};struct X { operator int();operator S();}; X a{}; S b{a}; — _end example_]
C.5.6 [library]: library introduction [diff.cpp11.library]
Affected subclause: [headers]
Change: New header.
Rationale: New functionality.
Effect on original feature: The C++ header is new.
Valid C++ 2011 code that #includes a header with that name may be invalid in this revision of C++.
C.5.7 [input.output]: input/output library [diff.cpp11.input.output]
Affected subclause: [c.files]
Change: gets is not defined.
Rationale: Use of gets is considered dangerous.
Effect on original feature: Valid C++ 2011 code that uses the gets function may fail to compile in this revision of C++.