Rationale: Required for new features
. Effect on original feature:
Valid C++ 2003 code may fail to compile or produce different results in
this International Standard
. Specifically, macros named
R,
u8,
u8R,
u,
uR,
U,
UR, or
LR will
not be expanded when adjacent to a string literal but will be interpreted as
part of the string literal
. For example,
#define u8 "abc"
const char* s = u8"def";
Rationale: Required for new features
. Effect on original feature:
Valid C++ 2003 code may fail to compile or produce different results in
this International Standard, as the following example illustrates
.
#define _x "there"
"hello"_x
Previously, #1 would have consisted of two separate preprocessing tokens and
the macro
_x would have been expanded
. In this International Standard,
#1 consists of a single preprocessing token, so the macro is not expanded
. Rationale: Required for new features
. Effect on original feature:
Added to Table
5, the following identifiers are new keywords:
alignas,
alignof,
char16_t,
char32_t,
constexpr,
decltype,
noexcept,
nullptr,
static_assert,
and
thread_local. Valid C++ 2003 code using these identifiers is invalid in this International
Standard
. Rationale: C99 compatibility
. Effect on original feature:
Certain integer literals larger than can be represented by
long could
change from an unsigned integer type to
signed long long. [conv.ptr]
Change: Only literals are integer null pointer constants
. Rationale: Removing surprising interactions with templates and constant
expressions
.
Effect on original feature: Valid C++ 2003 code may fail to compile or produce different results in
this International Standard, as the following example illustrates:
void f(void *); void f(...); template<int N> void g() {
f(0*N); }
[expr.mul]
Change: Specify rounding for results of integer
/ and
%. Rationale: Increase portability, C99 compatibility
. Effect on original feature:
Valid C++ 2003 code that uses integer division rounds the result toward 0 or
toward negative infinity, whereas this International Standard always rounds
the result toward 0
. Rationale: Required for new features
.
Effect on original feature:
Valid C++ 2003 code may fail to compile or produce different results in
this International Standard, as the following example illustrates:
bool b1 = new int && false; struct S { operator int(); };
bool b2 = &S::operator int && false;
[dcl.spec]
Change: Remove
auto as a storage class specifier
. Effect on original feature:
Valid C++ 2003 code that uses the keyword
auto as a storage class
specifier may be invalid in this International Standard
. In this International
Standard,
auto indicates that the type of a variable is to be deduced
from its initializer expression
. Effect on original feature:
Valid C++ 2003 code may fail to compile in this International Standard
. For
example, the following code is valid in C++ 2003 but invalid in this
International Standard because double to int is a narrowing
conversion:
Rationale: Improves template argument deduction failure
. Effect on original feature:
A valid C++ 2003 program that uses one of these special member functions in a
context where the definition is not required (e.g., in an expression that is
not potentially evaluated) becomes ill-formed
. [class.dtor] (destructors)
Change: User-declared destructors have an implicit exception specification
. Rationale: Clarification of destructor requirements
. Effect on original feature:
Valid C++ 2003 code may execute differently in this International Standard
. In
particular, destructors that throw exceptions will call
std::terminate
(without calling
std::unexpected) if their exception specification is
non-throwing
. Rationale: No implementation consensus
. Effect on original feature:
A valid C++ 2003 declaration containing
export is ill-formed in this
International Standard
. [temp.arg]
Change: Remove whitespace requirement for nested closing template right angle
brackets
. Rationale: Considered a persistent but minor annoyance
. Template aliases
representing non-class types would exacerbate whitespace issues
. Effect on original feature:
Change to semantics of well-defined expression
. A valid C++ 2003 expression
containing a right angle bracket (“
>”) followed immediately by
another right angle bracket may now be treated as closing two templates
. For example, the following code is valid in C++ 2003 because “
>>”
is a right-shift operator, but invalid in this International Standard because
“
>>” closes two templates
.
template <class T> struct X { };
template <int N> struct Y { };
X< Y< 1 >> 2 > > x;
Rationale: Overly constrained, simplify overload resolution rules
. Effect on original feature:
A valid C++ 2003 program could get a different result than this
International Standard
. Rationale: Required by new features
. Effect on original feature:
Valid C++ 2003 code that uses any identifiers added to the C++ standard
library by this International Standard may fail to compile or produce different
results in this International Standard
. A comprehensive list of identifiers used
by the C++ standard library can be found in the Index of Library Names in this
International Standard
. Rationale: New functionality
. Effect on original feature:
The following C++ headers are new:
<array>,
<atomic>,
<chrono>,
<codecvt>,
<condition_variable>,
<forward_list>,
<future>,
<initializer_list>,
<mutex>,
<random>,
<ratio>,
<regex>,
<scoped_allocator>,
<system_error>,
<thread>,
<tuple>,
<typeindex>,
<type_traits>,
<unordered_map>,
and
<unordered_set>. In addition the following C compatibility headers are new:
<ccomplex>,
<cfenv>,
<cinttypes>,
<cstdalign>,
<cstdbool>,
<cstdint>,
<ctgmath>,
and
<cuchar>. Valid C++ 2003 code that
#includes headers with these names may be
invalid in this International Standard
.[swappable.requirements]
Effect on original feature: Function
swap moved to a different header
Rationale: Remove dependency on
<algorithm> for
swap. Effect on original feature: Valid C++ 2003 code that has been compiled expecting swap to be in
<algorithm> may have to instead include
<utility>. Rationale: New functionality
. Effect on original feature:
The global namespace
posix is now reserved for standardization
. Valid
C++ 2003 code that uses a top-level namespace
posix may be invalid in
this International Standard
. Rationale: Avoid hard to diagnose or non-portable constructs
. Effect on original feature:
Names of attribute identifiers may not be used as macro names
. Valid C++
2003 code that defines
override,
final,
carries_dependency, or
noreturn as macros is invalid in this
International Standard
. Rationale: The two throwing single-object signatures of
operator new and
operator delete are now specified to form the base functionality for
the other operators
. This clarifies that replacing just these two signatures
changes others, even if they are not explicitly changed
. Effect on original feature:
Valid C++ 2003 code that replaces global
new or
delete
operators may execute differently in this International Standard
. For
example, the following program should write
"custom deallocation" twice,
once for the single-object delete and once for the array delete
.
#include <cstdio>
#include <cstdlib>
#include <new>
void* operator new(std::size_t size) throw(std::bad_alloc) {
return std::malloc(size);
}
void operator delete(void* ptr) throw() {
std::puts("custom deallocation");
std::free(ptr);
}
int main() {
int* i = new int;
delete i; int* a = new int[3];
delete [] a; }
Rationale: Consistent application of
noexcept. Effect on original feature:
Valid C++ 2003 code that assumes that global
operator new only
throws
std::bad_alloc may execute differently in this International
Standard
. Rationale: Required by new feature
. Effect on original feature:
Valid C++ 2003 code, compiled without traceable pointer support,
that interacts with newer C++ code using regions declared reachable may
have different runtime behavior
. Rationale: Superseded by new feature;
unary_function and
binary_function are no longer defined
. Effect on original feature:
Valid C++ 2003 code that depends on function object types being derived from
unary_function or
binary_function may fail to compile
in this International Standard
. [string.classes]
Change: basic_string requirements no longer allow reference-counted
strings
. Rationale: Invalidation is subtly different with reference-counted strings
. This change regularizes behavior for this International Standard
. Effect on original feature:
Valid C++ 2003 code may execute differently in this International Standard
. Rationale: Allow small-string optimization
. Effect on original feature:
Valid C++ 2003 code may execute differently in this International Standard
. Some
const member functions, such as
data and
c_str,
no longer invalidate iterators
. Rationale: Lack of specification of complexity of
size() resulted in
divergent implementations with inconsistent performance characteristics
. Effect on original feature:
Some container implementations that conform to C++ 2003 may not conform to the
specified
size() requirements in this International Standard
. Adjusting
containers such as
std::list to the stricter requirements may require
incompatible changes
. Rationale: Clarification
. Effect on original feature:
Valid C++ 2003 code that attempts to meet the specified container requirements
may now be over-specified
. Code that attempted to be portable across containers
may need to be adjusted as follows:
Rationale: Clarification of container requirements
. Effect on original feature:
Valid C++ 2003 code that attempts to explicitly instantiate a container using
a user-defined type with no default constructor may fail to compile
. Rationale: Old signature threw away useful information that may be expensive
to recalculate
. Effect on original feature:
The following member functions have changed:
erase(iter) for set, multiset, map, multimap
erase(begin, end) for set, multiset, map, multimap
insert(pos, num, val) for vector, deque, list, forward_list
insert(pos, beg, end) for vector, deque, list, forward_list
Valid C++ 2003 code that relies on these functions returning
void
(e.g., code that creates a pointer to member function that points to one
of these functions) will fail to compile with this International Standard
. Rationale: Overspecification
.
Effect on original feature:
The signatures of the following member functions changed from taking an
iterator to taking a const_iterator:
insert(iter, val) for vector, deque, list,
set, multiset, map, multimap
insert(pos, beg, end) for vector, deque, list,
forward_list
erase(begin, end) for set, multiset, map, multimap
all forms of list::splice
all forms of list::merge
Valid C++ 2003 code that uses these functions may fail to compile with this
International Standard
. Rationale: Performance, compatibility with move semantics
. Effect on original feature:
For
vector,
deque, and
list
the fill value passed to
resize is now passed by reference instead of
by value, and an additional overload of
resize has been added
. Valid
C++ 2003 code that uses this function may fail to compile with this International
Standard
.