Appendix C: ISO C++ 2003 Compatibility, Revision 1

 

ISO/IEC JTC1 SC22 WG21 N3186 = 10-0176 - 2010-11-26

Benjamin Kosnik, bkoz@redhat.com

 

Addresses: UK 6

 

 

Introduction

 

This paper details compatibility of C++ 2003 code, as compiled by this latest version of the C++ standard. It is based on ISO C++ draft N3126, and is a successor to N2733, Appendix C: ISO C++ 2003 Compatibility.

 

 

Proposed wording

 

Add a new section to Appendix C with the following contents.

 

C.2 C++ and ISO C++2003 [diff.iso.c++03]

 

The following subclauses list the differences between this version of C++ and the previous version of ISO C++ (ISO/IEC 14882:2003 Programming Languages - C++), by the chapters of this document.

 

 

C.2.1 Clause 2 lexical conventions

 

2.11

Change: New Keywords

Rationale: Required for new features.

Effect on original feature: Added to Table 3, the following identifiers are new keywords:alignof, char16_t, char32_t, constexpr, decltype,  noexcept, nullptr, static_assert, static_cast, and thread_local. Valid C++03 code using these identifiers is invalid in C++0x.

 

 

C.2.2 Clause 12 special member functions

 

12.4

Change: Destructors default to noexcept(true)

Rationale: Clarification of design with respect to unexpected termination.

Effect on original feature: Valid C++03 code may execute differently in C++0x.

 

 

C.2.3 Clause 14 templates

 

14.1

Change: Remove export.

Rationale: No implementation consensus.

Effect on original feature: A valid C++03 expression containing export is ill-formed in C++0x.

 

14.3

Change: Remove whitespace requirement for nested closing template right angle brackets

Rationale: Considered a persistent, but minor, annoyance. Template aliases representing nonclass types would exacerbate whitespace issues.

Effect on original feature: Change to semantics of well-defined expression. A valid C++03 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++03 (because ">>" is a right-shift operator) but invalid in C++0x (because the ">>" closes two templates:

   template<typename T> struct X { };

   template<int N> struct Y { };

   X< Y< 1 >> 2 > > x;

 

 

C.2.4 Clause 17 library introduction

 

17.6.1.2

Change: New includes.

Rationale: New functionality.

Effect on original feature: The following C++ include files are new: array, atomic, chrono, codecvt, condition_variable, forward_list, future, initializer_list, mutex, random, ratio, regex, scoped_allocator, sytem_error, thread, tuple, typeindex, and type_traits. In addition, the following C compatibility include files are new: ccomplex, cfenv, cinttypes, cstdbool, cstdint, ctgmath, and cuchar. Valid C++03 code that includes files with these names may be invalid in C++0x.

 

17.6.3.2.2

Change: New reserved namespace.

Rationale: New functionality.

Effect on original feature: The global namespace posix is now reserved for standardization. Valid C++03 code that used a top-level posix namespace may be invalid in C++0x.

 

 

C.2.5 Clause 18 library support

 

18.7

18.8

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x.

New identifiers, by include file:

 

<exception>

nested_exception, exception_ptr, current_exception, rethrow_exception, make_exception_ptr, throw_with_nested, and rethrow_if_nested.

 

<initializer_list>

initializer_list

 

 

18.6.1.1

Change: Linking new/delete operators.

Rationale: Two throwing single-object signatures form base for other operators, clarifies that replacing these two changes others. Tighter requirements increase portability.

Effect on original feature: Valid C++03 code that replaces global new/delete operators may execute differently in C++0x.

 

For example:

   #include <cstdio>

   #include <cstdlib>

   #include <new>

 

   void* operator new(std::size_t size) throw(std::bad_alloc)

   {

      std::printf("custom allocation\n");

      if (size == 0)

          size = 1;

      void*p = std::malloc(size);

      if (p == 0)

          throw std::bad_alloc();

      return p;

   }

 

   void  operator delete(void* ptr) throw()

   {

      std::printf("custom deallocation\n");

      std::free(ptr);

   }

 

   int main()

   {

      int* i = new int;

      delete i;

      int* a = new int[3];

      delete [] a;

   }

 

C.2.6 Clause 19 diagnostics

 

19.5

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<system_error>

error_category, error_code, error_condition, errc, system_error, is_error_code_enum, is_error_condition_enum, make_error_code, and make_error_condition.

 

19.4

Change: Thread-local error numbers.

Rationale: Support new thread facilities.

Effect on original feature: Valid but implementation-defined C++-03 code that relies on errno being the same across threads may change behavior in C++-0x.

 

 

C.2.7 Clause 20 utilities

 

20.1

20.3

20.4

20.5

20.7

20.8

20.9

20.10

20.11

20.13

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<chrono>

chrono, duration, duration_cast, time_point, time_point_cast, system_clock, monotonic_clock, high_resolution_clock

 

<memory>

pointer_traits, allocator_traits, allocator_arg, uses_allocator, is_scoped_allocator, constructible_with_allocator_suffix, constructible_with_allocator_prefix, allocator_propagate_never, allocator_propagate_on_copy_construction, allocator_propagate_on_move_assignment, allocator_propagate_on_copy_assignment, allocator_propagation_map, scoped_allocator_adaptor, construct_element, default_delete, unique_ptr, bad_weak_ptr, shared_ptr, static_pointer_cast, dynamic_pointer_cast, const_pointer_cast, get_deleter, weak_ptr, enable_shared_from_this, pointer_safety, declare_reachable, undeclare_reachable, declare_no_pointers, undeclare_no_pointers, get_pointer_safety, align

 

<ratio>

ratio, ratio_add, ratio_subtract, ratio_multiply, ratio_divide, ratio_equal, ratio_not_equal, ratio_less, ratio_less_equal, ratio_greater, ratio_greater_equal, yocto, zepto, atto, femto, pico, nano, micro, milli, centi, deci, deca, hecto, kilo, mega, giga, tera, peta, exa, zetta, and yotta.

 

<tuple>

tuple, uses_allocator, ignore, make_tuple, forward_as_tuple, tie, tuple_cat, tuple_size, tuple_element, get

 

<type_traits>

integral_constant, true_type, false_type, is_void, is_integral, is_floating_point, is_array, is_pointer, is_lvalue_reference, is_rvalue_reference, is_member_object_pointer, is_member_function_pointer, is_enum, is_union, is_class, is_function, is_reference, is_arithmetic, is_fundamental, is_member_pointer, is_scalar, is_object, is_compound, is_const, is_volatile, is_trivial, is_standard_layout, is_pod, is_empty, is_polymorphic, is_abstract, remove_const, remove_volatile, remove_cv, add_const, add_volatile, add_cv, remove_reference, add_reference, remove_pointer, add_pointer, is_signed, is_unsigned, rank, extent, remove_extent, remove_all_extents, has_trivial_default_contructor, has_trivial_copy_constructor, has_trivial_assign, has_trivial_destructor, has_nothrow_default_constructor, has_nothrow_copy_constructor, has_nothrow_assign, has_virtual_destructor, is_same, is_base_of, is_convertible,  aligned_storage, aligned_union, decay, enable_if, conditional, common_type

 

 

C.2.8 Clause 21 strings

 

21.2

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<string>

u16string, u32string, stoi, stol, stoul, stoll, stoull, stof, stod, stold, to_string, to_wstring

 

21.3

Change: Change basic_string requirements to disallow reference counted strings.

Rationale: Invalidation subtly different between reference-counted strings and other implementation strategies. Regularize behavior for new C++0x features.

Effect on original feature: C++03 code may execute differently in C++0x.

 

 

C.2.9 Clause 23 containers

 

23.2

Change: Specify size() complexity to be constant.

Rationale: Lack of size() specification results in divergent implementations with inconsistent performance characteristics.

Effect on original feature: Some container implementations in C++03 may not conform to the specified size() requirements in C++0x. Adjusting containers (such as list) to the stricter requirements may require incompatible changes.

 

23.2

23.4

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<array>

array

 

<forward_list>

forward_list

 

<unordered_map>

unordered_map, unordered_multimap

 

<unordered_set>

unordered_set, unordered_multiset

 

 

C.2.10 Clause 25 algorithms

 

25

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<algorithm>

all_of, any_of, none_of, find_if_not, copy_n, copy_if, partition_copy, partition_point

 

 

C.2.11 Clause 26 numerics

 

26.4.2

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<random>

linear_congruential_engine, mersenne_twister_engine, subtract_with_carry_engine, discard_block_engine, independent_bits_engine, shuffle_order_engine, minstd_rand0, minstd_rand, mt19937, ranlux24_base, ranlux48_bse, ranlux24, ranlux48, knuth_b, default_random_engine, random_device, seed_seq, generate_cannonical, uniform_int_distribution, uniform_real_distribution, bernoulli_distribution, binomial_distribution, geometric_distribution, negative_binomial_distribution, poisson_distribution, exponential_distribution, gamma_distribution, weibull_distribution, extreme_value_distribution, normal_distribution, lognormal_distribution, chi_squared_distribution, cauchy_distribution, fisher_f_distribution, student_t_distribution, discrete_distribution, piecewise_constant_distribution, general_pdf_distribution

 

 

C.2.12 Clause 27 io

 

27.3

Change: Specify behavior for concurrent access to standard streams.

Rationale: Standardizing existing behavior.

Effect on original feature: Define race-free concurrent access for synchronized streams. C++03 code may execute differently in C++0x.

 

27.4.2

Change: Change base class of ios_base::failure.

Rationale: Detailed error messages.

Effect on original feature: Define ios_base::failure base class as system_error. C++03 code may execute differently in C++0x.

 

27.5.2

Change: Change ios_base:: types from enumerations to formalized bitmasks represented as constexpr member data.

Rationale: All bitmask types should be defined as enumerations with mask operators implemented as constexpr functions.

Effect on original feature: Define ios_base::fmtflags, ios_base::iostate, ios_base::openmode, ios_base::seekdir as formalized bitmask types.

Some code that depended on the implementation properties of these types being std::bitset or a builtin integer type may no longer compile.

 

For example:

 

  #include <iostream>

   std::cout.setf(17); // should be std::cout.setf(hex);

 

 

C.2.13 Clause 28 regex

 

28.4

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<regex>

regex_constants, regex_error, regex_traits, basic_regex, regex, wregex, sub_match, csub_match, wcsub_match, ssub_match, wssub_match, match_results, cmatch, wcmatch, smatch, wsmatch, regex_match, regex_search, regex_replace, regex_iterator, cregex_iterator, wcregex_iterator, sregex_iterator, wsregex_iterator, regex_token_iterator, cregex_token_iterator, wcregex_token_iterator, sregex_token_iterator, wsregex_token_iterator.

 

 

C.2.14 Clause 29 atomics

 

29.0

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<atomic>

memory_order, kill_dependency, atomic_flag, atomic, atomic_bool, atomic_char, atomic_schar, atomic_uchar, atomic_short, atomic_ushort, atomic_int, atomic_uint, atomic_long, atomic_ulong, atomic_llong, atomic_ullong, atomic_wchar_t, atomic_char16_t, atomic_char32_t

 

 

C.2.15 Clause 30 threads

 

30.3

30.4

30.5

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++03 code that uses these identifiers may be invalid in C++0x. New identifiers, by include file:

 

<thread>

thread, this_thread

 

<mutex>

mutex, recursive_mutex, timed_mutex, recursive_timed_mutex, defer_lock_t, try_to_lock_t, adopt_lock_t, defer_lock, try_to_lock, adopt_lock, try_lock, lock, once_flag, call_once, lock_guard, unique_lock

 

<condition_variable>

condition_variable, condition_variable_any, cv_status, notify_all_at_thread_exit

 

 

References

 

N2270 Incompatible Changes in C++0x

N2733 Appendix C: ISO C++ 2003 Compatibility

N3126 Draft Programing Languages - C++, Pete Becker

N3204 Deducing 'noexcept' for destructors

N3205 Delete operators default to noexcept

N3110 Problems with bitmask types in the library

N3064 Core issue 374: Explicit specialization outside a template's parent (revision 1)

N3065 Removing Export

N3068 Equality Comparison for Unordered Containers (Rev 2)

N2923 Specifying the complexity of size() (Revision 1)

N2760 Input/Output Library Thread Safety

N2769 Detailed Reporting for Input/Output Library Errors (Revision 2)

N2668 Concurrency Modifications to Basic String

N2680 Proposed Wording for Placement Insert (Revision 1)