Document: N2733=08-0243

Date: 2008-08-22

Authors: Benjamin Kosnik <bkoz@redhat.com>


Appendix C: ISO C++ 2003 Compatibility


General organization and editorial suggestions


This paper proposes a new section in Appendix C for compatibility between ISO C++ 2003 and ISO C++200x.


Because of the significant added text in this section, a re-organization of Appendix C is advised. Suggest collapsing

C.1 C++ and ISO C

and

C.2 Standard C library


into one grouping for both language and library features, such that


C.1 C++ and ISO C
C.1.1 Clause 2: lexical conventions

...

C.1.9 Clause 16: preprocessing directives [diff.cpp]


remain as-is, and then


C.1.10 Clause 18

C.1.11 Clause 20

C.1.11 Clause 21


are added, and the contents of


C.2.1

C.2.2

C.2.3

C.2.4


are moved into the appropriate place in C.1.*. Consider this an editorial suggestion.


Then, start with the C++2003 Compatibility with


C.2 C++ and ISO C++2003


And the rest of the text as is follows in this document.


If this arrangement is considered poor, then the existing layout can be used and C.3 C++ and ISO C++2003 can be used instead, and the text of this document can be added with the obvious transformation for whatever approved numbering scheme is in effect by the editor.


Proposed wording

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: alignas, alignof, char16_t, char32_t, constexpr, decltype,  nullptr, static_cast, and thread_local. Valid C++03 code using these identifiers is invalid in C++0x.


C.2.2 Clause 14 templates

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.3 Clause 17 library introduction


17.4.1.3

Change: New includes.
Rationale: New functionality.
Effect on original feature: The following C++ include files are new: array, chrono, initializer_list, mutex, random, ratio, regex, sytem_error, and threads. 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.4.3.1.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.4 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, copy_exception, throw_with_nested, and rethrow_if_nested.


<initializer_list>

initializer_list



18.5.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()
    {
  &nb! sp; 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.5 Clause 19 diagnostics


19.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:


<system_error>
error_category, error_code, error_condition, system_error, is_error_code_enum, is_error_condition_enum, make_error_code, and make_error_condition.

19.3

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.6 Clause 20 utilities


20.1
20.3
20.4
20.5
20.7
20.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:


<chrono>
chrono

<memory>
allocator_tag_t, allocator_arg_t, 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, atomic_is_lock_free, atomic_load, atomic_load_explicit, atomic_store, atomic_store_explicit, atomic_exchange, atomic_exchange_explicit, atomic_compare_exchange, atomic_compare_exchange_explicit

<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, constructible_with_allocator_prefix

<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


<utility>

tuple_size, tuple_element, get



C.2.7 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


C.2.8 Clause 23 containers


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, tuple_element, tuple_size, get


<forward_list>

forward_list


<unordered_map>

unordered_map, unordered_multimap


<unordered_set>

unordered_set, unordered_multiset



C.2.9 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.10 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.11 Clause 27 io


27.4.1

Change: Change ios_base:: types that are bitmasks to be an enumeration with constexpr overloads.
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 enumerations.

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.12 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.13 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:


<cstdatomic>

memory_order, kill_dependency, atomic_flag, atomic_flag_test_and_set, atomic_flag_test_and_set_explicit, atomic_flag_clear, atomic_flag_clear_explicit, atomic_flag_fence, atomic_global_fence_compatibility, atomic_is_lock_free, atomic_store, atomic_store_explicit, atomic_load, atomic_load_explicit, atomic_exchange, atomic_exchange_explicit, atomic_compare_exchange, atomic_compare_exchange_explicit, atomic_fence, atomic_fence, atomic_fetch_add, atomic_fetch_add_explicit, atomic_fetch_sub, atomic_fetch_sub_explicit, atomic, atomic_address, 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.14 Clause 30 threads


30.2

30.3

30.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:


<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


<condition_variable>

condition_variable, condition_variable_any



References

Benjamin Kosnik, Matt Austern, "Incompatible Changes in C++0x," N2270=07-0130

Jens Maurer, "Requirements on programs and backwards compatibility," N2693 08-0203

Daveed Vandevoorde, "Right Angle Brackets," N1757=05-0017

Gabriel Dos Reis, Bjarne Stroustrup, "Constant Expressions in the Standard Library - Revision 2," N2349=07-0209

Howard Hinnant, "LWG Issue 206: Linking new/delete operators," N2158=07-0018

Pete Becker, "Draft Programing Languages - C++," N2691

Lawrence Crowl, "Thread-Local Storage," N2659=08-0169

John Spicer, J. Stephen Adamczyk, "Solving the SFINAE problem for expressions," N2634=08-0144

Matt Austern, "STL singly linked lists (revision 3)," N2543=08-0053