Annex C (informative) Compatibility [diff] (original) (raw)
C.4 C++ and ISO C++ 2014 [diff.cpp14]
C.4.1 General [diff.cpp14.general]
Subclause [diff.cpp14] lists the differences between C++ and ISO C++ 2014, in addition to those listed above, by the chapters of this document.
C.4.2 [lex]: lexical conventions [diff.cpp14.lex]
Affected subclause: [lex.phases]
Change: Removal of trigraph support as a required feature.
Rationale: Prevents accidental uses of trigraphs in non-raw string literals and comments.
Effect on original feature: Valid C++ 2014 code that uses trigraphs may not be valid or may have different semantics in this revision of C++.
Implementations may choose to translate trigraphs as specified in C++ 2014 if they appear outside of a raw string literal, as part of theimplementation-defined mapping from input source file characters to the translation character set.
Affected subclause: [lex.ppnumber]
Effect on original feature: Valid C++ 2014 code may fail to compile or produce different results in this revision of C++.
Specifically, character sequences like 0p+0and 0e1_p+0 are three separate tokens each in C++ 2014, but one single token in this revision of C++.
[Example 1: #define F(a) b ## aint b0p = F(0p+0); — _end example_]
C.4.3 [expr]: expressions [diff.cpp14.expr]
Affected subclauses: [expr.post.incr] and [expr.pre.incr]
Change: Remove increment operator with bool operand.
Rationale: Obsolete feature with occasionally surprising semantics.
Effect on original feature: A valid C++ 2014 expression utilizing the increment operator on a bool lvalue is ill-formed in this revision of C++.
Affected subclauses: [expr.new] and [expr.delete]
Change: Dynamic allocation mechanism for over-aligned types.
Rationale: Simplify use of over-aligned types.
Effect on original feature: In C++ 2014 code that uses a new-expressionto allocate an object with an over-aligned class type, where that class has no allocation functions of its own,::operator new(std::size_t)is used to allocate the memory.
In this revision of C++,::operator new(std::size_t, std::align_val_t)is used instead.
C.4.4 [dcl]: declarations [diff.cpp14.dcl.dcl]
Affected subclause: [dcl.stc]
Rationale: Enable repurposing of deprecated keyword in future revisions of C++.
Effect on original feature: A valid C++ 2014 declaration utilizing the register storage-class-specifier is ill-formed in this revision of C++.
The specifier can simply be removed to retain the original meaning.
Affected subclause: [dcl.spec.auto]
Rationale: More intuitive deduction behavior.
Effect on original feature: Valid C++ 2014 code may fail to compile or may change meaning in this revision of C++.
[Example 1: auto x1{1}; auto x2{1, 2}; — _end example_]
Affected subclause: [dcl.fct]
Change: Make exception specifications be part of the type system.
Rationale: Improve type-safety.
Effect on original feature: Valid C++ 2014 code may fail to compile or change meaning in this revision of C++.
[Example 2: void g1() noexcept;void g2();template<class T> int f(T *, T *);int x = f(g1, g2); — _end example_]
Affected subclause: [dcl.init.aggr]
Change: Definition of an aggregate is extended to apply to user-defined types with base classes.
Rationale: To increase convenience of aggregate initialization.
Effect on original feature: Valid C++ 2014 code may fail to compile or produce different results in this revision of C++; initialization from an empty initializer list will perform aggregate initialization instead of invoking a default constructor for the affected types.
[Example 3: struct derived;struct base { friend struct derived;private: base();};struct derived : base {}; derived d1{}; derived d2; — _end example_]
C.4.5 [class]: classes [diff.cpp14.class]
Affected subclause: [class.inhctor.init]
Change: Inheriting a constructor no longer injects a constructor into the derived class.
Rationale: Better interaction with other language features.
Effect on original feature: Valid C++ 2014 code that uses inheriting constructors may not be valid or may have different semantics.
A using-declarationthat names a constructor now makes the corresponding base class constructors visible to initializations of the derived class rather than declaring additional derived class constructors.
[Example 1: struct A { template<typename T> A(T, typename T::type = 0); A(int);};struct B : A { using A::A; B(int);}; B b(42L); — _end example_]
C.4.6 [temp]: templates [diff.cpp14.temp]
Affected subclause: [temp.deduct.type]
Change: Allowance to deduce from the type of a constant template argument.
Rationale: In combination with the ability to declare constant template arguments with placeholder types, allows partial specializations to decompose from the type deduced for the constant template argument.
Effect on original feature: Valid C++ 2014 code may fail to compile or produce different results in this revision of C++.
[Example 1: template <int N> struct A;template <typename T, T N> int foo(A<N> *) = delete;void foo(void *);void bar(A<0> *p) { foo(p); } — _end example_]
C.4.7 [except]: exception handling [diff.cpp14.except]
Affected subclause: [except.spec]
Change: Remove dynamic exception specifications.
Rationale: Dynamic exception specifications were a deprecated feature that was complex and brittle in use.
They interacted badly with the type system, which became a more significant issue in this revision of C++ where (non-dynamic) exception specifications are part of the function type.
Effect on original feature: A valid C++ 2014 function declaration, member function declaration, function pointer declaration, or function reference declaration, if it has a potentially throwing dynamic exception specification, is rejected as ill-formed in this revision of C++.
Violating a non-throwing dynamic exception specification calls terminate rather than unexpected, and it is unspecified whether stack unwinding is performed prior to such a call.
C.4.8 [library]: library introduction [diff.cpp14.library]
Affected subclause: [headers]
Change: New headers.
Rationale: New functionality.
Effect on original feature: The following C++ headers are new:,,,,,,
Valid C++ 2014 code that #includes headers with these names may be invalid in this revision of C++.
Affected subclause: [namespace.future]
Change: New reserved namespaces.
Rationale: Reserve namespaces for future revisions of the standard library that might otherwise be incompatible with existing programs.
Effect on original feature: The global namespaces stdfollowed by an arbitrary sequence of digits ([lex.name]) are reserved for future standardization.
Valid C++ 2014 code that uses such a top-level namespace, e.g., std2, may be invalid in this revision of C++.
C.4.9 [utilities]: general utilities library [diff.cpp14.utilities]
Affected subclause: [func.wrap]
Change: Constructors taking allocators removed.
Rationale: No implementation consensus.
Effect on original feature: Valid C++ 2014 code may fail to compile or may change meaning in this revision of C++.
Specifically, constructing a std::function with an allocator is ill-formed and uses-allocator construction will not pass an allocator to std::function constructors in this revision of C++.
Affected subclause: [util.smartptr.shared]
Change: Different constraint on conversions from unique_ptr.
Rationale: Adding array support to shared_ptr, via the syntax shared_ptr<T[]> and shared_ptr<T[N]>.
Effect on original feature: Valid C++ 2014 code may fail to compile or may change meaning in this revision of C++.
[Example 1: #include <memory>std::unique_ptr<int[]> arr(new int[1]); std::shared_ptr<int> ptr(std::move(arr)); — _end example_]
C.4.10 [strings]: strings library [diff.cpp14.string]
Affected subclause: [basic.string]
Change: Non-const .data() member added.
Rationale: The lack of a non-const .data()differed from the similar member of std::vector.
This change regularizes behavior.
Effect on original feature: Overloaded functions which have differing code paths for char* and const char* arguments will execute differently when called with a non-const string's .data() member in this revision of C++.
[Example 1: int f(char *) = delete;int f(const char *); string s;int x = f(s.data()); — _end example_]
C.4.11 [containers]: containers library [diff.cpp14.containers]
Affected subclause: [associative.reqmts]
Change: Requirements change:
Rationale: Increase portability, clarification of associative container requirements.
Effect on original feature: Valid C++ 2014 code that attempts to use associative containers having a comparison object with non-const function call operator may fail to compile in this revision of C++.
[Example 1: #include <set> struct compare{ bool operator()(int a, int b) { return a < b;} };int main() { const std::set<int, compare> s; s.find(0);} — _end example_]
C.4.12 [depr]: compatibility features [diff.cpp14.depr]
Change: The class templatesauto_ptr,unary_function, andbinary_function, the function templatesrandom_shuffle, and the function templates (and their return types)ptr_fun,mem_fun,mem_fun_ref,bind1st, andbind2ndare not defined.
Rationale: Superseded by new features.
Effect on original feature: Valid C++ 2014 code that uses these class templates and function templates may fail to compile in this revision of C++.
Change: Remove old iostreams members [depr.ios.members].
Rationale: Redundant feature for compatibility with pre-standard code has served its time.
Effect on original feature: A valid C++ 2014 program using these identifiers may be ill-formed in this revision of C++.