コンテンツにスキップ

C++/互換性

出典: フリー教科書『ウィキブックス(Wikibooks)』
< C++


ここでは、C23の作業中の草稿 N4950 の Annex C (informative) Compatibility [diff] にコメンタリを加える形で互換性への注意を解説します。

C.1 C++ and ISO C++ 2020 [diff.cpp20][編集]

C.1.1 General [diff.cpp20.general][編集]

1 Subclause C.1 lists the differences between C++ and ISO C++ 2020 (ISO/IEC 14882:2020, Programming Languages — C++), by the chapters of this document.

この節では、C++とISO C++ 2020(ISO/IEC 14882:2020, プログラミング言語 — C++)の違いを章ごとにリストしています。

C.1.2 Clause 5: lexical conventions [diff.cpp20.lex][編集]

1 Affected subclause: 5.10

Change
Previously valid identifiers containing characters not present in UAX #44 properties XID_Start or XID_Continue, or not in Normalization Form C, are now rejected.
変更点
以前は有効だった、UAX #44プロパティXID_StartまたはXID_Continueに含まれない文字、または正規化形式Cにない文字を含む識別子が、現在は拒否されます。
Rationale
Prevent confusing characters in identifiers. Requiring normalization of names ensures consistent linker behavior.
理由
識別子に混乱を招く文字を防ぐため。名前の正規化を要求することで、一貫したリンカの動作を確保します。
Effect on original feature
Some identifiers are no longer well-formed.
元の機能への影響
一部の識別子がもはや正しく形成されません。

2 Affected subclause: 5.13.5

Change
Concatenated string-literals can no longer have conflicting encoding-prefixes.
変更点
連結された文字列リテラルは、エンコーディングプレフィックスが矛盾していることができなくなります。
Rationale
Removal of unimplemented conditionally-supported feature.
理由
実装されていない条件付きサポート機能の削除。
Effect on original feature
Concatenation of string-literals with different encoding-prefixes is now ill-formed. For example:
元の機能への影響
異なるエンコーディングプレフィックスを持つ文字列リテラルの連結が不正になります。例えば:  :
auto c = L"a" U"b"; // was conditionally-supported; now ill-formed
背景事情
以前のC++では、UAX #44プロパティのXID_StartやXID_Continueに含まれない文字や、正規化形式C(NFC)に準拠していない文字を含む識別子が有効でした。これにより、一見すると非常に似ているが異なる識別子が作成される可能性があり、コードの可読性とメンテナンス性が低下する恐れがありました。これを防ぐために、識別子の形式を厳格化することで、一貫性のあるリンク動作を確保し、混乱を避けるようにしました。
また以前のC++では、異なるエンコーディングプレフィックスを持つ文字列リテラルを連結することが条件付きでサポートされていましたが、実際には実装されていないことが多かったです。このような条件付きサポートの機能を削除することで、仕様を簡素化し、一貫した動作を保証します。

C.1.3 Clause 7: expressions [diff.cpp20.expr][編集]

1 Affected subclause: 7.5.4.2

Change
Change move-eligible id-expressions from lvalues to xvalues.
変更点
ムーブ対象のid式をlvalueからxvalueに変更します。
Rationale
Simplify the rules for implicit move.
理由
暗黙のムーブのルールを簡素化するため。
Effect on original feature
Valid C++ 2020 code that relies on a returned id-expression’s being an lvalue may change behavior or fail to compile. For example:
元の機能への影響
戻り値のid式がlvalueであることに依存している有効なC++ 2020コードが動作を変更するか、コンパイルに失敗する可能性があります。例えば:
decltype(auto) f(int&& x) { return (x); } // returns int&&; previously returned int&
int& g(int&& x) { return x; } // ill-formed; previously well-formed
背景事情
C++20以前では、id-expressionがlvalueとして扱われる場合がありましたが、これが複雑なルールの原因となっていました。これをxvalueに変更することで、暗黙のmove操作に関するルールを簡素化し、より直感的で一貫した動作を提供します。

2 Affected subclause: 7.6.1.2

Change
Change the meaning of comma in subscript expressions.
変更点
添字式内のコンマの意味を変更します。
Rationale
Enable repurposing a deprecated syntax to support multidimensional indexing.
理由
廃止された構文を再利用して多次元インデックスをサポートできるようにするため。
Effect on original feature
Valid C++ 2020 code that uses a comma expression within a subscript expression may fail to compile. For example:
元の機能への影響
添字式内でコンマ式を使用している有効なC++ 2020コードがコンパイルに失敗する可能性があります。例えば:
arr[1, 2] // was equivalent to arr[(1, 2)],
          // now equivalent to arr.operator[](1, 2) or ill-formed
背景事情
サブスクリプト式内でのカンマの意味を変更することで、従来の非推奨の構文を再利用し、多次元インデックスをサポートするための新しい構文を導入しました。これにより、コードの可読性と柔軟性が向上します。

C.1.4 Clause 8: statements [diff.cpp20.stmt][編集]

1 Affected subclause: 8.6.5

Change
The lifetime of temporary objects in the for-range-initializer is extended until the end of the loop (6.7.7).
変更点
for-range初期化子内の一時オブジェクトのライフタイムがループの終了まで延長されます(6.7.7)。
Rationale
Improve usability of the range-based for statement.
理由
範囲ベースのfor文の使いやすさを向上させるため。
Effect on original feature
Destructors of some temporary objects are invoked later. For example:
元の機能への影響
一部の一時オブジェクトのデストラクタが後で呼び出されます。例えば:
void f() {
    std::vector<int> v = { 42, 17, 13 };
    std::mutex m;
    for (int x : static_cast<void>(std::lock_guard<std::mutex>(m)), v) { // lock released in C++ 2020
        std::lock_guard<std::mutex> guard(m); // OK in C++ 2020, now deadlocks
    }
}
背景事情
range-based forループのイニシャライザ内の一時オブジェクトのライフタイムをループの終了まで延長することで、一時オブジェクトのデストラクタがループ内で呼び出されることを防ぎ、コードの安全性と予測可能性を向上させます。

C.1.5 Clause 9: declarations [diff.cpp20.dcl][編集]

1 Affected subclause: 9.4.3

Change
UTF-8 string literals may initialize arrays of char or unsigned char.
変更点
UTF-8文字列リテラルでcharまたはunsigned charの配列を初期化できるようになります。
Rationale
Compatibility with previously written code that conformed to previous versions of this document.
理由
本書の以前のバージョンに準拠した既存のコードとの互換性を確保するため。
Effect on original feature
Arrays of char or unsigned char may now be initialized with a UTF-8 string literal. This can affect initialization that includes arrays that are directly initialized within class types, typically aggregates. For example:
元の機能への影響
charまたはunsigned charの配列がUTF-8文字列リテラルで初期化されるようになりました。これにより、クラス型内で直接初期化される配列(通常は集約)の初期化に影響を与える可能性があります。例えば:
struct A {
    char8_t s[10];
};
struct B {
    char s[10];
};
void f(A);
void f(B);
int main() {
    f({u8""}); // ambiguous
}
背景事情
UTF-8文字列リテラルでcharやunsigned charの配列を初期化できるようにすることで、以前のバージョンのC++との互換性を維持します。これにより、特にクラス型内で直接初期化される配列の初期化に関するコードの可読性と移植性が向上します。

C.1.6 Clause 13: templates [diff.cpp20.temp][編集]

1 Affected subclause: 13.10.3.6

Change
Deducing template arguments from exception specifications.
変更点
例外仕様からテンプレート引数を推定する。
Rationale
Facilitate generic handling of throwing and non-throwing functions.
理由
例外を投げる関数と投げない関数の一般的な取り扱いを容易にするため。
Effect on original feature
Valid ISO C++ 2020 code may be ill-formed in this revision of C++. For example:
元の機能への影響
この改訂版のC++では、ISO C++ 2020で有効なコードが不正になる可能性があります。例えば:
template<bool> struct A { };
template<bool B> void f(void (*)(A<B>) noexcept(B));
void g(A<false>) noexcept;
void h() {
    f(g); // ill-formed; previously well-formed
}
背景事情
例外仕様からテンプレート引数を推論することで、throwingとnon-throwingの関数を一般的に扱いやすくなります。これにより、テンプレートプログラミングの柔軟性が向上しますが、一部の既存のC++ 2020コードがコンパイルエラーになる可能性があります。

C.1.7 Clause 16: library introduction [diff.cpp20.library][編集]

1 Affected subclause: 16.4.2.3

Change
New headers.
変更点
新しいヘッダが追加されました。
Rationale
New functionality.
理由
新しい機能を提供するため。
Effect on original feature
The following C++ headers are new: <expected> (22.8.2), <flat_map> (24.6.4), <flat_set> (24.6.5), <generator> (26.8.2), <print> (31.7.4), <spanstream> (31.9.2), <stacktrace> (19.6.2), and <stdatomic.h> (33.5.12). Valid C++ 2020 code that #includes headers with these names may be invalid in this revision of C++.
元の機能への影響
以下のC++ヘッダが新しく追加されました: <expected> (22.8.2), <flat_map> (24.6.4), <flat_set> (24.6.5), <generator> (26.8.2), <print> (31.7.4), <spanstream> (31.9.2), <stacktrace> (19.6.2), および <stdatomic.h> (33.5.12)。これらの名前でヘッダをインクルードする有効なC++ 2020コードは、この改訂版のC++では無効になる可能性があります。
背景事情
新しいヘッダファイルの追加により、標準ライブラリの機能が拡張されました。これにより、より多くの機能が標準ライブラリでサポートされるようになり、ユーザーがサードパーティのライブラリに依存する必要性が減ります。

C.1.8 Clause 18: concepts library [diff.cpp20.concepts][編集]

1 Affected subclauses: 17.11.4, 18.5.4, and 18.5.5

Change
Replace common_reference_with in three_way_comparable_with, equality_comparable_with, and totally_ordered_with with an exposition-only concept.
変更点
three_way_comparable_with、equality_comparable_with、およびtotally_ordered_withにおけるcommon_reference_withを説明専用のコンセプトに置き換えます。
Rationale
Allow uncopyable, but movable, types to model these concepts.
理由
コピー不可だがムーブ可能な型がこれらのコンセプトをモデル化できるようにするため。
Effect on original feature
Valid C++ 2020 code relying on subsumption with common_reference_with may fail to compile in this revision of C++. For example:
元の機能への影響
common_reference_withによる包含に依存する有効なC++ 2020コードが、この改訂版のC++ではコンパイルに失敗する可能性があります。例えば:
template<class T, class U>
requires equality_comparable_with<T, U>
bool attempted_equals(const T&, const U& u); // previously selected overload

template<class T, class U>
requires common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&>
bool attempted_equals(const T& t, const U& u); // ambiguous overload; previously
// rejected by partial ordering

bool test(shared_ptr<int> p) {
    return attempted_equals(p, nullptr); // ill-formed; previously well-formed
}
背景事情
common_reference_withを説明専用のコンセプトに置き換えることで、コピー不可だがムーブ可能な型がこれらのコンセプトをモデル化できるようになり、テンプレートプログラミングの柔軟性が向上します。

C.1.9 Clause 20: memory management library [diff.cpp20.memory][編集]

1 Affected subclause: 20.2.9.1

Change
Forbid partial and explicit program-defined specializations of allocator_traits.
変更点
allocator_traitsの部分および明示的なプログラム定義の特殊化を禁止します。
Rationale
Allow addition of allocate_at_least to allocator_traits, and potentially other members in the future.
理由
allocator_traitsにallocate_at_leastを追加し、将来的には他のメンバーを追加できるようにするため。
Effect on original feature
Valid C++ 2020 code that partially or explicitly specializes allocator_traits is ill-formed with no diagnostic required in this revision of C++.
元の機能への影響
allocator_traitsを部分的または明示的に特殊化する有効なC++ 2020コードは、この改訂版のC++では診断なしで不正になります。
背景事情
allocator_traitsの部分および明示的な特殊化を禁止することで、新しいメンバー(例えばallocate_at_least)の追加が可能となり、将来的な拡張が容易になります。

C.1.10 Clause 22: general utilities library [diff.cpp20.utilities][編集]

1 Affected subclause: 22.14

Change
Signature changes: format, format_to, vformat_to, format_to_n, formatted_size. Removal of format_args_t.
変更点
シグネチャの変更: format, format_to, vformat_to, format_to_n, formatted_size。format_args_tの削除。
Rationale
Improve safety via compile-time format string checks, avoid unnecessary template instantiations.
理由
コンパイル時のフォーマット文字列チェックを通じて安全性を向上させ、不必要なテンプレートのインスタンス化を回避するため。
Effect on original feature
Valid C++ 2020 code that contained errors in format strings or relied on previous format string signatures or format_args_t may become ill-formed. For example:
元の機能への影響
フォーマット文字列にエラーが含まれていたり、以前のフォーマット文字列のシグネチャやformat_args_tに依存していた有効なC++ 2020コードが不正になる可能性があります。例えば:
; auto s = std : :format("{:d}", "I am not a number"); // ill-formed, previously threw format_error

2 Affected subclause: 22.14

Change
Signature changes: format, format_to, format_to_n, formatted_size.
変更点
シグネチャの変更: format, format_to, format_to_n, formatted_size。
Rationale
Enable formatting of views that do not support iteration when const-qualified and that are not copyable.
理由
const修飾された場合にイテレーションをサポートしないビューや、コピーできないビューのフォーマットを可能にするため。
Effect on original feature
Valid C++ 2020 code that passes bit fields to formatting functions may become ill-formed. For example:
元の機能への影響
ビットフィールドをフォーマット関数に渡す有効なC++ 2020コードが不正になる可能性があります。例えば:
struct tiny {
    int bit: 1;
};
auto t = tiny();
std::format("{}", t.bit); // ill-formed, previously returned "0"

3 Affected subclause: 22.14.2.2

Change
Restrict types of formatting arguments used as width or precision in a std-format-spec.
変更点
std-format-specで幅または精度として使用されるフォーマット引数の型を制限します。
Rationale
Disallow types that do not have useful or portable semantics as a formatting width or precision.
理由
フォーマット幅や精度として有用または移植可能なセマンティクスを持たない型を禁止するため。
Effect on original feature
Valid C++ 2020 code that passes a boolean or character type as arg-id becomes invalid. For example:
元の機能への影響
arg-idとしてブール型または文字型を渡す有効なC++ 2020コードが無効になります。例えば:
std::format("{:*^{}}", "", true); // ill-formed, previously returned "*"
std::format("{:*^{}}", "", '1'); // ill-formed, previously returned an implementation-defined number of ’*’ characters

4 Affected subclause: 22.14.6.3

Change
Removed the formatter specialization:
変更点
formatterの特殊化が削除されました:
template<size_t N> struct formatter<const charT[N], charT>;
Rationale
The specialization is inconsistent with the design of formatter, which is intended to be instantiated only with cv-unqualified object types.
理由
この特殊化は、formatterがcv修飾されていないオブジェクト型のみをインスタンス化するように設計されていることと矛盾するため。
Effect on original feature
Valid C++ 2020 code that instantiated the removed specialization can become ill-formed.
元の機能への影響
削除された特殊化をインスタンス化する有効なC++ 2020コードが不正になる可能性があります。
背景事情
フォーマット文字列に関するコンパイル時チェックの強化と、不要なテンプレートインスタンスの回避により、安全性が向上し、フォーマット機能の柔軟性が高まります。また、ビューのフォーマットが可能になることで、イテレーションをサポートしないビューやコピー不可能なビューのフォーマットも容易になります。

C.1.11 Clause 23: strings library [diff.cpp20.strings][編集]

1 Affected subclause: 23.4

Change
Additional rvalue overload for the substr member function and the corresponding constructor.
変更点
substrメンバー関数および対応するコンストラクタにrvalueオーバーロードが追加されました。
Rationale
Improve efficiency of operations on rvalues.
理由
rvalueに対する操作の効率を向上させるため。
Effect on original feature
Valid C++ 2020 code that created a substring by calling substr (or the corresponding constructor) on an xvalue expression with type S that is a specialization of basic_string may change meaning in this revision of C++. For example:
元の機能への影響
basic_stringの特殊化である型Sのxvalue式に対してsubstr(または対応するコンストラクタ)を呼び出してサブ文字列を作成する有効なC++ 2020コードの意味が、この改訂版のC++では変更される可能性があります。例えば:
std::string s1 = "some long string that forces allocation", s2 = s1;
std::move(s1).substr(10, 5);
assert(s1 == s2); // unspecified, previously guaranteed to be true
std::string s3(std::move(s2), 10, 5);
assert(s1 == s2); // unspecified, previously guaranteed to be true
背景事情
rvalueに対するsubstrメンバー関数および対応するコンストラクタのオーバーロードを追加することで、効率的な操作が可能になり、パフォーマンスが向上します。

C.1.12 Clause 24: containers library [diff.cpp20.containers][編集]

1 Affected subclauses: 24.2.7 and 24.2.8

Change
Heterogeneous extract and erase overloads for associative containers.
変更点
連想コンテナに対する異種抽出および消去オーバーロードが追加されました。
Rationale
Improve efficiency of erasing elements from associative containers.
理由
連想コンテナから要素を消去する効率を向上させるため。
Effect on original feature
Valid C++ 2020 code may fail to compile in this revision of C++. For example:
元の機能への影響
有効なC++ 2020コードがこの改訂版のC++ではコンパイルに失敗する可能性があります。例えば:
struct B {
    auto operator<=>(const B&) const = default;
};
; struct D  :  private B {
    void f(std::set<B, std::less<>>& s) {
        s.erase(*this); // ill-formed; previously well-formed
    }
};
背景事情
連想コンテナに対する異種抽出および消去オーバーロードの追加により、要素の消去操作がより効率的になり、パフォーマンスが向上します。

C.1.13 Clause 33: concurrency support library [diff.cpp20.thread][編集]

1 Affected subclause: 33.9.3

Change
In this revision of C++, it is implementation-defined whether a barrier’s phase completion step runs if no thread calls wait. Previously the phase completion step was guaranteed to run on the last thread that calls arrive or arrive_and_drop during the phase. In this revision of C++, it can run on any of the threads that arrived or waited at the barrier during the phase.
変更点
この改訂版のC++では、バリアのフェーズ完了ステップが、スレッドがwaitを呼び出さない場合に実行されるかどうかが実装定義となります。以前は、フェーズ中にarriveまたはarrive_and_dropを呼び出した最後のスレッドでフェーズ完了ステップが実行されることが保証されていましたが、この改訂版のC++では、フェーズ中にバリアに到達したか待機したスレッドのいずれかで実行される可能性があります。
Rationale
Correct contradictory wording and improve implementation flexibility for performance.
理由
矛盾した表現を修正し、パフォーマンス向上のために実装の柔軟性を改善するため。
Effect on original feature
Valid C++ 2020 code using a barrier might have different semantics in this revision of C++ if it depends on a completion function’s side effects occurring exactly once, on a specific thread running the phase completion step, or on a completion function’s side effects occurring without wait having been called. For example:
元の機能への影響
完了関数の副作用が正確に一度だけ発生すること、特定のスレッドがフェーズ完了ステップを実行すること、またはwaitが呼び出されずに完了関数の副作用が発生することに依存する場合、バリアを使用する有効なC++ 2020コードは、この改訂版のC++で異なる意味を持つ可能性があります。例えば:
auto b0 = std::barrier(1);
b0.arrive();
b0.arrive(); // implementation-defined; previously well-defined

int data = 0;
auto b1 = std::barrier(1, [&] { data++; });
b1.arrive();
assert(data == 1); // implementation-defined; previously well-defined
b1.arrive(); // implementation-defined; previously well-defined
背景事情
バリアのフェーズ完了ステップに関する実装の柔軟性を高めることで、パフォーマンスの向上を図りつつ、矛盾した表現を修正します。これにより、バリアの動作が実装依存になる可能性がありますが、より効率的な実装が可能となります。

C.2 C++ and ISO C++ 2017 [diff.cpp17][編集]

C.2.1 General [diff.cpp17.general][編集]

1 Subclause C.2 lists the differences between C++ and ISO C++ 2017 (ISO/IEC 14882:2017, Programming Languages — C++), by the chapters of this document.

一般的な説明です。このセクションでは、C++とISO C++ 2017の違いがこの文書の章ごとにリスト化されています。

C.2.2 Clause 5: lexical conventions [diff.cpp17.lex][編集]

Affected subclauses: 5.4, 10.1, 10.3, 15.1, 15.4, and 15.5
Change: New identifiers with special meaning.
Rationale: Required for new features.
Effect on original feature: Logical lines beginning with module or import may be interpreted differently in this revision of C++.

この節では、5節の構文規則に影響を与える変更について述べています。特別な意味を持つ新しい識別子が導入され、これは新しい機能のために必要です。具体的には、"module"や"import"から始まる論理行が、このC++の改訂版では異なる解釈を受ける可能性があります。

C.2.3 Clause 6: basics [diff.cpp17.basic][編集]

Affected subclause: 6.7.3
Change: A pseudo-destructor call ends the lifetime of the object to which it is applied.
Rationale: Increase consistency of the language model.
Effect on original feature: Valid ISO C++ 2017 code may be ill-formed or have undefined behavior in this revision of C++.

この節では、6節の基本に影響を与える変更について述べています。疑似デストラクタ呼び出しによってオブジェクトのライフタイムが終了するようになり、これは言語モデルの一貫性を高めるためです。しかし、この変更により、有効なISO C++ 2017コードがこの改訂版のC++では不正なものになる可能性があります。

C.2.4 Clause 7: expressions [diff.cpp17.expr][編集]

Affected subclause: 7.5.5.3
Change: Implicit lambda capture may capture additional entities.
Rationale: Rule simplification, necessary to resolve interactions with constexpr if.
Effect on original feature: Lambdas with a capture-default may capture local entities that were not captured in C++ 2017 if those entities are only referenced in contexts that do not result in an odr-use.

この節では、7節の式に影響を与える変更について述べています。暗黙のラムダキャプチャが追加のエンティティをキャプチャできるようになり、これはconstexpr ifとの相互作用を解決するために必要な単純化されたルールです。ただし、この変更により、キャプチャされたエンティティがodr-useを引き起こさないコンテキストでのみ参照されている場合、C++ 2017ではキャプチャされなかったローカルエンティティをキャプチャするラムダが可能になります。

C.2.5 Clause 9: declarations [diff.cpp17.dcl.dcl][編集]

Affected subclause: 9.2.4
Change: Unnamed classes with a typedef name for linkage purposes can contain only C-compatible constructs.
Rationale: Necessary for implementability.
Effect on original feature: Valid C++ 2017 code may be ill-formed in this revision of C++.

この節では、9節の宣言に影響を与える変更について述べています。リンケージ目的のtypedef名を持つ名前なしのクラスは、C互換の構造のみを含むことができるようになりました。これは、実装可能性のために必要な変更ですが、C++ 2017の有効なコードがこの改訂版のC++では不正なものになる可能性があります。

C.2.6 Clause 11: classes [diff.cpp17.class][編集]

Affected subclauses: 11.4.5 and 11.4.8.3
Change: The class name can no longer be used parenthesized immediately after an explicit decl-specifier in a constructor declaration. The conversion-function-id can no longer be used parenthesized immediately after an explicit decl-specifier in a conversion function declaration.
Rationale: Necessary for new functionality.
Effect on original feature: Valid C++ 2017 code may fail to compile in this revision of C++.

この節では、11節のクラスに影響を与える変更について述べています。クラス名は、コンストラクタ宣言で明示的な宣言指定子の直後に括弧で囲まれた形で使用できなくなりました。また、変換関数宣言で明示的な宣言指定子の直後に括弧で囲まれた形で使用できなくなりました。これは新しい機能のために必要な変更ですが、有効なC++ 2017コードがこの改訂版のC++ではコンパイルに失敗する可能性があります。

C.2.7 Clause 12: overloading [diff.cpp17.over][編集]

Affected subclause: 12.2.2.3
Change: Equality and inequality expressions can now find reversed and rewritten candidates.
Rationale: Improve consistency of equality with three-way comparison and make it easier to write the full complement of equality operations.
Effect on original feature: For certain pairs of types where one is convertible to the other, equality or inequality expressions between an object of one type and an object of the other type invoke a different operator.

この節では、12節のオーバーロードに影響を与える変更について述べています。等価および非等価式は、逆および書き換えられた候補を見つけることができるようになりました。これは、等価性を三方向比較と一貫性を持たせ、等価操作の完全な補完を書きやすくするために行われました。ただし、特定の型のペアでは、一方の型のオブジェクトともう一方の型のオブジェクトの間の等価性または非等価性式が異なる演算子を呼び出すことがあります。

C.2.8 Clause 13: templates [diff.cpp17.temp][編集]

Affected subclause: 13.3
Change: An unqualified-id that is followed by a < and for which name lookup finds nothing or finds a function will be treated as a template-name in order to potentially cause argument dependent lookup to be performed.
Rationale: It was problematic to call a function template with an explicit template argument list via argument dependent lookup because of the need to have a template with the same name visible via normal lookup.
Effect on original feature: Previously valid code that uses a function name as the left operand of a < operator would become ill-formed.

この節では、13節のテンプレートに影響を与える変更について述べています。特定の条件を満たすunqualified-idが現れた場合、これがテンプレート名として扱われ、引数依存の名前検索が行われる可能性があります。これは、通常の検索を介して同じ名前のテンプレートを見る必要があるため、引数依存の検索を介して明示的なテンプレート引数リストを持つ関数テンプレートを呼び出すことが問題であったためです。以前に有効だったコードが、<演算子の左オペランドとして関数名を使用する場合、不正な形式になる可能性があります。

C.2.9 Clause 14: exception handling [diff.cpp17.except][編集]

Affected subclause: 14.5
Change: Remove throw() exception specification.
Rationale: Removal of obsolete feature that has been replaced by noexcept.
Effect on original feature: A valid C++ 2017 function declaration, member function declaration, function pointer declaration, or function reference declaration that uses throw() for its exception specification will be rejected as ill-formed in this revision of C++.

この節では、14節の例外処理に影響を与える変更について述べられています。throw()例外仕様が削除され、これは時代遅れの機能であり、noexceptに置き換えられました。この改訂版のC++では、throw()を使用している関数宣言、メンバ関数宣言、関数ポインタ宣言、または関数参照宣言は不正形式として拒否されます。

C.2.10 Clause 16: library introduction [diff.cpp17.library][編集]

Affected subclause: 16.4.2.3
Change: New headers.
Rationale: New functionality.
Effect on original feature: The following C++ headers are new: <barrier>, <bit>, <charconv>, <compare>, <concepts>, <coroutine>, <format>, <latch>, <numbers>, <ranges>, <semaphore>, <source_location>, <span>, <stop_token>, <syncstream>, and <version>. Valid C++ 2017 code that #includes headers with these names may be invalid in this revision of C++.

この節では、16節のライブラリ導入に影響を与える変更について述べられています。新しいヘッダが導入され、これは新しい機能を反映しています。新しいヘッダには、<barrier>、<bit>、<charconv>、<compare>、<concepts>、<coroutine>、<format>、<latch>、<numbers>、<ranges>、<semaphore>、<source_location>、<span>、<stop_token>、<syncstream>、および<version>が含まれます。これらの名前のヘッダを含む有効なC++ 2017コードは、この改訂版のC++では無効になる可能性があります。

C.2.11 Clause 24: containers library [diff.cpp17.containers][編集]

Affected subclauses: 24.3.9 and 24.3.10
Change: Return types of remove, remove_if, and unique changed from void to container::size_type.
Rationale: Improve efficiency and convenience of finding number of removed elements.
Effect on original feature: Code that depends on the return types might have different semantics in this revision of C++. Translation units compiled against this version of C++ may be incompatible with translation units compiled against C++ 2017, either failing to link or having undefined behavior.

この節では、24節のコンテナライブラリに影響を与える変更について述べられています。remove、remove_if、およびuniqueの戻り値の型がvoidからcontainer::size_typeに変更されました。これは、削除された要素の数を見つける効率と便利さを向上させるためです。これに依存するコードは、この改訂版のC++では異なるセマンティクスを持つ可能性があります。このバージョンのC++でコンパイルされた翻訳ユニットは、C++ 2017でコンパイルされた翻訳ユニットと互換性がなくなる可能性があり、リンクに失敗するか、未定義の動作をするかもしれません。

C.2.12 Clause 25: iterators library [diff.cpp17.iterators][編集]

Affected subclause: 25.3.2.3
Change: The specialization of iterator_traits for void* and for function pointer types no longer contains any nested typedefs.
Rationale: Corrects an issue misidentifying pointer types that are not incrementable as iterator types.
Effect on original feature: A valid C++ 2017 program that relies on the presence of the typedefs may fail to compile, or have different behavior.

この節では、25節のイテレータライブラリに影響を与える変更について述べられています。void*および関数ポインタタイプのiterator_traitsの特殊化には、もはや任意のネストされたtypedefが含まれていません。これは、イテレータタイプではないポインタタイプを誤って識別する問題を修正するためです。これに依存する有効なC++ 2017プログラムは、typedefの存在に依存している場合、コンパイルに失敗するか、異なる動作をする可能性があります。

C.2.13 Clause 27: algorithms library [diff.cpp17.alg.reqs][編集]

Affected subclause: 27.2
Change: The number and order of deducible template parameters for algorithm declarations is now unspecified, instead of being as-declared.
Rationale: Increase implementor freedom and allow some function templates to be implemented as function objects with templated call operators.
Effect on original feature: A valid C++ 2017 program that passes explicit template arguments to algorithms not explicitly specified to allow such in this version of C++ may fail to compile or have undefined behavior.

この節では、27節のアルゴリズムライブラリに影響を与える変更について述べられています。アルゴリズム宣言のための推論可能なテンプレートパラメータの数と順序は、宣言されたままではなく、未指定になりました。これは、実装者の自由度を増やし、一部の関数テンプレートをテンプレート化された呼び出し演算子を持つ関数オブジェクトとして実装することを可能にするためです。このバージョンのC++で明示的にそのようなものを許可するように明示的に指定されていないアルゴリズムに対して明示的なテンプレート引数を渡す有効なC++ 2017プログラムは、コンパイルに失敗するか、未定義の動作をする可能性があります。

C.2.14 Clause 31: input/output library [diff.cpp17.input.output][編集]

Affected subclause: 31.7.5.3.3
Change: Character array extraction only takes array types.
Rationale: Increase safety via preventing buffer overflow at compile time.
Effect on original feature: Valid C++ 2017 code may fail to compile in this revision of C++. For example:
auto p = new char[100];
char q[100]; std::cin >> std::setw(20) >> p; // ill-formed; previously well-formed std::cin >> std::setw(20) >> q; // OK

この節では、31節の入出力ライブラリに影響を与える変更について述べられています。文字配列の抽出は、もはや配列タイプのみを受け入れます。これは、バッファオーバーフローをコンパイル時に防止することで安全性を高めるためです。この改訂版のC++では、有効なC++ 2017コードがコンパイルに失敗する場合があります。例えば、

Affected subclause: 31.7.6.3.4
Change: Overload resolution for ostream inserters used with UTF-8 literals.
Rationale: Required for new features.
Effect on original feature: Valid C++ 2017 code that passes UTF-8 literals to basic_ostream<char, ...>::operator<< or basic_ostream<wchar_t, ...>::operator<< is now ill-formed. For example:
std::cout << u8"text"; // previously called operator<<(const char*) and printed a string; // now ill-formed std::cout << u8'X'; // previously called operator<<(char) and printed a character; // now ill-formed

この節では、31節の入出力ライブラリに影響を与える変更について述べられています。UTF-8リテラルを使用したostream挿入子のオーバーロードの解決方法が変更されました。これは、新機能のために必要です。この変更により、basic_ostream<char, ...>::operator<< または basic_ostream<wchar_t, ...>::operator<< にUTF-8リテラルを渡す有効なC++ 2017コードが、この改訂版では不適切となります。

C.3 C++ and ISO C++ 2014 [diff.cpp14][編集]

C.3.1 General [diff.cpp14.general][編集]

  1. Subclause C.3 lists the differences between C++ and ISO C++ 2014 (ISO/IEC 14882:2014, Programming Languages — C++), in addition to those listed above, by the chapters of this document.

C.3.2 Clause 5: lexical conventions [diff.cpp14.lex][編集]

  1. Affected subclause: 5.2 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 the implementation-defined mapping from input source file characters to the translation character set.

トライグラフは歴史的な符号化サポートで、実際の使用は稀です。トライグラフは間違って使われることが多く、予期しない動作を引き起こす可能性があります。これを取り除くことで、コードの可読性と保守性が向上します。

  1. Affected subclause: 5.9 Change: pp-number can contain p sign and P sign. Rationale: Necessary to enable hexadecimal-floating-point-literals. 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+0 and 0e1_p+0 are three separate tokens each in C++ 2014, but one single token in this revision of C++. For example:

16進浮動小数点リテラルをサポートするためにpp-numberの仕様が変更されました。この変更により、以前は複数のトークンとして解釈されていた文字列が単一のトークンとして扱われるようになります。

C.3.3 Clause 7: expressions [diff.cpp14.expr][編集]

  1. Affected subclauses: 7.6.1.6 and 7.6.2.3 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++.

bool型に対するインクリメント演算子は意味が曖昧であり、予期せぬ結果を招くことがあります。これを削除することでコードの予測可能性と明瞭性が向上します。

  1. Affected subclauses: 7.6.2.8 and 7.6.2.9 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-expression to 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.3.4 Clause 9: declarations [diff.cpp14.dcl.dcl][編集]

  1. Affected subclause: 9.2.2 Change: Removal of register storage-class-specifier. 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.

registerストレージクラス指定子は現在ほとんどのコンパイラで無視されており、最適化の自動化が進んだ現代では不要です。これを削除することで、将来的にキーワードを他の目的で再利用できるようにします。

  1. Affected subclause: 9.2.9.6 Change: auto deduction from braced-init-list. 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++. For example:

中括弧初期化リストからのauto型推論が直感的になりました。これにより、一部のコードは以前のバージョンと異なる意味を持つ可能性があります。

  1. Affected subclause: 9.3.4.6 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++. For example:

例外仕様を型システムの一部にすることで、型安全性が向上します。これにより、以前は有効だったコードがコンパイルエラーを引き起こす可能性があります。

  1. Affected subclause: 9.4.2 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. For example:

アグリゲートの定義が基底クラスを持つユーザー定義型にも適用されるようになりました。これにより、空の初期化リストからの初期化がアグリゲート初期化として扱われるようになり、既存のコードがエラーとなる場合があります。

C.3.5 Clause 11: classes [diff.cpp14.class][編集]

  1. Affected subclause: 11.9.4 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-declaration that names a constructor now makes the corresponding base class constructors visible to initializations of the derived class rather than declaring additional derived class constructors. For example:

継承コンストラクタの使用宣言が派生クラスのコンストラクタを注入するのではなく、基底クラスのコンストラクタを可視化するようになりました。これにより、他の言語機能との相互作用が改善されます。

C.3.6 Clause 13: templates [diff.cpp14.temp][編集]

  1. Affected subclause: 13.10.3.6 Change: Allowance to deduce from the type of a non-type template argument. Rationale: In combination with the ability to declare non-type template arguments with placeholder types, allows partial specializations to decompose from the type deduced for the non-type template argument. Effect on original feature: Valid C++ 2014 code may fail to compile or produce different results in this revision of C++. For example:

非型テンプレート引数の型から推論する機能が追加されました。これにより、非型テンプレート引数の部分特殊化が可能になりますが、以前のコードがコンパイルエラーとなる場合があります。

C.3.7 Clause 14: exception handling [diff.cpp14.except][編集]

  1. Affected subclause: 14.5 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.3.8 Clause 16: library introduction [diff.cpp14.library][編集]

  1. Affected subclause: 16.4.2.3 Change: New headers. Rationale: New functionality. Effect on original feature: The following C++ headers are new: <any> (22.7.2), <charconv> (22.13.1), <execution> (22.12.2), <filesystem> (31.12.4), <memory_resource> (20.4.1), <optional> (22.5.2), <string_view> (23.3.2), and <variant> (22.6.2). Valid C++ 2014 code that #includes headers with these names may be invalid in this revision of C++.

新しいヘッダが追加され、機能が拡張されました。これにより、コードが新しい機能を利用できるようになりますが、以前のコードが無効になる可能性もあります。

  1. Affected subclause: 16.4.5.2.3 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 std followed by an arbitrary sequence of digits (5.10) 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.3.9 Clause 22: general utilities library [diff.cpp14.utilities][編集]

  1. Affected subclause: 22.10.17 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++.

アロケータを受け取るコンストラクタが削除されました。これにより、std::functionの構築方法が変更され、以前のコードがコンパイルエラーとなる可能性があります。

  1. Affected subclause: 20.3.2.2 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++. For example:

shared_ptrに配列サポートが追加されました。これにより、unique_ptrからの変換に異なる制約が適用されるようになります。

C.3.10 Clause 23: strings library [diff.cpp14.string][編集]

  1. Affected subclause: 23.4.3 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++. For example:**

std::stringに非constのdata()メンバ関数が追加されました。これにより、std::vectorとの一貫性が向上しますが、オーバーロードされた関数の挙動が変わる可能性があります。

C.3.11 Clause 24: containers library [diff.cpp14.containers][編集]

  1. Affected subclause: 24.2.7 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++. For example:

比較オブジェクトに非constの関数呼び出し演算子を持つ連想コンテナの要件が変更されました。これにより、移植性が向上しますが、一部のコードがコンパイルエラーになる可能性があります。

C.3.12 Annex D: compatibility features [diff.cpp14.depr][編集]

  1. Change: The class templates auto_ptr, unary_function, and binary_function, the function templates random_shuffle, and the function templates (and their return types) ptr_fun, mem_fun, mem_fun_ref, bind1st, and bind2nd are 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++.

auto_ptrunary_functionなどのクラステンプレート、およびrandom_shuffleなどの関数テンプレートは、新しい機能によって置き換えられたため削除されました。これにより、以前のコードがコンパイルエラーとなる可能性があります。

  1. 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++.

古いiostreamメンバーが削除されました。これにより、前標準コードとの互換性がなくなり、以前のコードが無効になる可能性があります。

C.4 C++ and ISO C++ 2011 [diff.cpp11][編集]

C.4.1 General [diff.cpp11.general][編集]

  1. Subclause C.4 lists the differences between C++ and ISO C++ 2011 (ISO/IEC 14882:2011, Programming Languages — C++), in addition to those listed above, by the chapters of this document.

C.4.2 Clause 5: lexical conventions [diff.cpp11.lex][編集]

  1. Affected subclause: 5.9 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++. For example:

この変更は、数字の区切りとしてアポストロフィを使用するためのものです。C++ 2011では、アポストロフィは文字リテラルとして扱われますが、この改訂版では数字の区切りとして扱われるため、マクロの解釈が異なります。これにより、以前のコードが意図しない動作をする可能性があります。

C.4.3 Clause 6: basics [diff.cpp11.basic][編集]

  1. Affected subclause: 6.7.5.5.3 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:

In this revision of C++, however, the declaration of operator delete might match a predefined usual (non-placement) operator delete (6.7.5.5). If so, the program is ill-formed, as it was for class member allocation functions and deallocation functions (7.6.2.8).

新しい標準では、サイズ付きのデアロケータが導入されました。これにより、以前のコードでグローバルな配置デアロケータを宣言すると、標準の通常のデアロケータと一致する可能性があり、その場合コードが無効になる可能性があります。

C.4.4 Clause 7: expressions [diff.cpp11.expr][編集]

  1. Affected subclause: 7.6.16 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 (7.3.2), array-to-pointer (7.3.3), and function-to-pointer (7.3.4) standard 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++. For example:

In C++ 2011, f(true) returns 1. In this revision of C++, it returns 2.

条件演算子の中に例外を投げるthrow式が含まれる場合、C++ 2011では型と値カテゴリが変更されるため一時オブジェクトが生成される可能性があります。この動作は予想外であると考えられたため、新しい標準では、もう一方のオペランドの型と値カテゴリを保持するようになりました。これにより、以前のコードの動作が変わる可能性があります。

C.4.5 Clause 9: declarations [diff.cpp11.dcl.dcl][編集]

  1. Affected subclause: 9.2.6 Change: constexpr non-static member functions are not implicitly const 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++. For example:

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.

この変更は、constexpr メンバー関数がオブジェクトを変更できるようにするために必要でした。C++ 2011では、constexprの非静的メンバー関数は暗黙的にconstメンバー関数と見なされましたが、この改訂版ではそれがなくなり、同じメンバー関数を異なる戻り値の型で2回宣言することはできません。

  1. Affected subclause: 9.4.2 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++. For example:

デフォルトメンバー初期化子を持つクラスがアグリゲートと見なされるようになりました。これにより、アグリゲート初期化を使用してデフォルトメンバー初期化子を利用できるようになります。C++ 2011ではコピーコンストラクタが使用されていた場合でも、新しい標準ではアグリゲート初期化が行われるため、コードの動作が変わる可能性があります。

C.4.6 Clause 16: library introduction [diff.cpp11.library][編集]

  1. Affected subclause: 16.4.2.3 Change: New header. Rationale: New functionality. Effect on original feature: The C++ header <shared_mutex> (33.6.3) is new. Valid C++ 2011 code that #includes a header with that name may be invalid in this revision of C++.

新しい機能を追加するために、新しいヘッダー<shared_mutex>が導入されました。C++ 2011で同名のヘッダーをインクルードしているコードは、この改訂版では無効になる可能性があります。

C.4.7 Clause 31: input/output library [diff.cpp11.input.output][編集]

  1. Affected subclause: 31.13 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++.

gets関数は安全ではないと見なされているため、この改訂版では定義されていません。これにより、C++ 2011でgets関数を使用しているコードは、この改訂版ではコンパイルエラーとなる可能性があります。

C.5 C++ and ISO C++ 2003 [diff.cpp03][編集]

この節では、ISO C++ 2003とC++の違いについての詳細がリストされています。

この変更は、新しい機能をサポートするために必要なものです。C++の文字列リテラルに新しい種類が追加されました。しかし、この変更により、以前のC++ 2003のコードであっても、マクロが文字列リテラルの隣にある場合には展開されず、文字列リテラルの一部として解釈される可能性があります。

C.5.2 Clause 5: lexical conventions [diff.cpp03.lex][編集]

1 Affected subclause: 5.4

Change: New kinds of string-literals.

Rationale: Required for new features.

Effect on original feature: Valid C++ 2003 code may fail to compile or produce different results in this revision of C++. 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:

この変更は、新しい機能をサポートするために必要なものです。C++の文字列リテラルに新しい種類が追加されました。しかし、この変更により、以前のC++ 2003のコードであっても、マクロが文字列リテラルの隣にある場合には展開されず、文字列リテラルの一部として解釈される可能性があります。

C.5.3 Clause 7: expressions [diff.cpp03.expr][編集]

1 Affected subclause: 7.3.12

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 revision of C++. For example:

この変更は、テンプレートや定数式との意図しない相互作用を取り除くために行われました。以前のC++ 2003では、整数のnullポインタ定数としてリテラル以外のものも許可されていましたが、これは予測できない振る舞いを引き起こす可能性がありました。例えば、テンプレートを使って整数のnullポインタを渡す場合、以前は特定の関数が呼ばれていたのに、この変更により別の関数が呼ばれる可能性があります。

C.5.4 Clause 9: declarations [diff.cpp03.dcl.dcl][編集]

1 Affected subclause: 9.2

Change: Remove auto as a storage class specifier.

Rationale: New feature.

Effect on original feature: Valid C++ 2003 code that uses the keyword auto as a storage class specifier may be invalid in this revision of C++. In this revision of C++, auto indicates that the type of a variable is to be deduced from its initializer expression.

この変更は、新しい機能をサポートするために行われました。以前のC++ 2003コードで、autoキーワードを変数の記憶クラス指定子として使用している場合、この変更によりコンパイルエラーが発生する可能性があります。この変更により、autoは変数の初期化式から型を推論することを示すものとして使用されます。

C.5.5 Clause 11: classes [diff.cpp03.class][編集]

1 Affected subclauses: 11.4.5.2, 11.4.7, 11.4.5.3, and 11.4.6

Change: Implicitly-declared special member functions are defined as deleted when the implicit definition would have been ill-formed.

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.

この変更は、テンプレート引数の推論の失敗を改善するために行われました。以前のC++ 2003では、特定の状況下で暗黙的に宣言された特殊メンバ関数の定義が不要な場合でも、その定義が削除されることはありませんでした。しかし、この変更により、そのような場合には定義が削除されるようになり、以前は有効であったC++ 2003のプログラムが無効になる可能性があります。

C.5.6 Clause 13: templates [diff.cpp03.temp][編集]

1 Affected subclause: 13.2

Change: Repurpose export for modules (Clause 10, 15.4, 15.5).

Rationale: No implementation consensus for the C++ 2003 meaning of export.

Effect on original feature: A valid C++ 2003 program containing export is ill-formed in this revision of C++.

この変更は、C++ 2003のexportの意味について実装の合意がないため、モジュール(Clause 10, 15.4, 15.5)のためにexportを再利用するために行われました。この変更により、exportを含む有効なC++ 2003プログラムは、このC++の改訂版では不正なものとされます。

C.5.7 Clause 16: library introduction [diff.cpp03.library][編集]

1 Affected: Clause 16 – Clause 33

Change: New reserved identifiers.

Rationale: Required by new features.

Effect on original feature: Valid C++ 2003 code that uses any identifiers added to the C++ standard library by later revisions of C++ may fail to compile or produce different results in this revision of C++.

この変更は、新しい機能で必要とされるようになった新しい予約語の追加を意味します。C++の標準ライブラリに後の改訂版で追加された任意の識別子を使用する有効なC++ 2003コードは、この改訂版のC++ではコンパイルに失敗するか、異なる結果を生じる可能性があります。

C.5.8 Clause 17: language support library [diff.cpp03.language.support][編集]

1 Affected subclause: 17.6.3.2

Change: operator new may throw exceptions other than std::bad_alloc.

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 revision of C++. Valid C++ 2003 code that replaces the global replaceable operator new is ill-formed in this revision of C++, because the exception specification of throw(std::bad_alloc) was removed.

この変更は、noexceptの一貫した適用を目的として行われました。以前のC++ 2003では、グローバルなoperator newstd::bad_alloc以外の例外をスローすることはありませんでした。しかし、この改訂版では、throw(std::bad_alloc)の例外仕様が削除されたため、この仕様を置き換える有効なC++ 2003コードは不正とされます。

C.5.9 Clause 19: diagnostics library [diff.cpp03.diagnostics][編集]

1 Affected subclause: 19.4

Change: Thread-local error numbers.

Rationale: Support for new thread facilities.

Effect on original feature: Valid but implementation-specific C++ 2003 code that relies on errno being the same across threads may change behavior in this revision of C++.

この変更は、新しいスレッド機能をサポートするために行われました。スレッド間でerrnoが同じであることに依存する実装固有のC++ 2003コードは、この改訂版のC++では動作が変わる可能性があります。

C.5.10 Clause 22: general utilities library [diff.cpp03.utilities][編集]

1 Affected subclauses: 22.10.6, 22.10.7, 22.10.8, 22.10.10, and 22.10.11

Change: Standard function object types no longer derived from std::unary_function or std::binary_- function.

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 revision of C++.

この変更は、新機能によって置き換えられたため、標準関数オブジェクト型がもはやstd::unary_functionまたはstd::binary_functionから派生しなくなったことを示しています。unary_functionおよびbinary_functionはもはや定義されていないため、これらに依存する有効なC++ 2003コードは、この改訂版のC++でコンパイルに失敗する可能性があります。

C.5.11 Clause 23: strings library [diff.cpp03.strings][編集]

1 Affected subclause: 23.4

Change: basic_string requirements no longer allow reference-counted strings.

Rationale: Invalidation is subtly different with reference-counted strings. This change regularizes behavior.

Effect on original feature: Valid C++ 2003 code may execute differently in this revision of C++.

この変更は、参照カウントされた文字列を許可しないように、basic_stringの要件が変更されたことを示しています。参照カウントされた文字列では無効化の振る舞いが微妙に異なるため、この変更により振る舞いが正規化されます。この改訂版のC++では、有効なC++ 2003コードが異なる方法で実行される可能性があります。

C.5.12 Clause 24: containers library [diff.cpp03.containers][編集]

1 Affected subclause: 24.2

Change: Complexity of size() member functions now constant.

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 revision of C++. Adjusting containers such as std::list to the stricter requirements may require incompatible changes.

この変更は、size()メンバ関数の複雑さが定数になったことを示しています。size()の複雑さの仕様の欠如により、一貫性のないパフォーマンス特性を持つ異なる実装が生じました。C++ 2003に準拠した一部のコンテナ実装は、この改訂版のC++で指定されたsize()の要件に準拠しない場合があります。std::listなどのコンテナをより厳しい要件に合わせるためには、非互換の変更が必要となるかもしれません。

C.5.13 Clause 27: algorithms library [diff.cpp03.algorithms][編集]

1 Affected subclause: 27.1

Change: Result state of inputs after application of some algorithms.

Rationale: Required by new feature.

Effect on original feature: A valid C++ 2003 program may detect that an object with a valid but unspecified state has a different valid but unspecified state with this revision of C++. For example, std::remove and std::remove_if may leave the tail of the input sequence with a different set of values than previously.

この変更は、いくつかのアルゴリズムの適用後の入力の状態が変わることを示しています。この変更は、新しい機能によって必要とされました。この改訂版のC++では、有効だが未指定の状態を持つオブジェクトが、以前とは異なる有効だが未指定の状態になる可能性があります。たとえば、std::removestd::remove_ifは、入力シーケンスの末尾に以前とは異なる値のセットを残す可能性があります。

C.5.14 Clause 28: numerics library [diff.cpp03.numerics][編集]

1 Affected subclause: 28.4

Change: Specified representation of complex numbers.

Rationale: Compatibility with C99.

Effect on original feature: Valid C++ 2003 code that uses implementation-specific knowledge about the binary representation of the required template specializations of std::complex may not be compatible with this revision of C++.

この変更は、複素数の指定された表現方法が変更されたことを示しています。C99との互換性を保つための変更です。この改訂版のC++では、std::complexの必要なテンプレート特殊化のバイナリ表現についての実装固有の知識を使用する有効なC++ 2003コードが、互換性のない可能性があります。

C.5.15 Clause 30: localization library [diff.cpp03.locale][編集]

1 Affected subclause: 30.4.3.2.3

Change: The num_get facet recognizes hexadecimal floating point values.

Rationale: Required by new feature.

Effect on original feature: Valid C++ 2003 code may have different behavior in this revision of C++.

この変更は、num_getファセットが16進浮動小数点値を認識するようになったことを示しています。新機能に必要な変更です。この改訂版のC++では、有効なC++ 2003コードが異なる動作をする可能性があります。

C.5.16 Clause 31: input/output library [diff.cpp03.input.output][編集]

1 Affected subclauses: 31.7.5.2.4, 31.7.6.2.4, and 31.5.4.4

Change: Specify use of explicit in existing boolean conversion functions.

Rationale: Clarify intentions, avoid workarounds.

Effect on original feature: Valid C++ 2003 code that relies on implicit boolean conversions will fail to compile with this revision of C++. Such conversions occur in the following conditions: (1.1) — passing a value to a function that takes an argument of type bool; (1.2) — using operator== to compare to false or true; (1.3) — returning a value from a function with a return type of bool; (1.4) — initializing members of type bool via aggregate initialization; (1.5) — initializing a const bool& which would bind to a temporary object.

この変更は、既存のブール変換関数でのexplicitの使用を明確にし、回避策を防ぐために行われました。暗黙のブール変換に依存する有効なC++ 2003コードは、この改訂版のC++ではコンパイルに失敗するでしょう。このような変換は以下の条件で発生します:

  • 関数にbool型の引数を取る関数に値を渡す場合
  • operator==を使用してfalseまたはtrueと比較する場合
  • 戻り値がbool型の関数から値を返す場合
  • 集約初期化を使用してbool型のメンバを初期化する場合
  • 一時オブジェクトにバインドされるconst bool&を初期化する場合

2 Affected subclause: 31.5.2.2.1

Change: Change base class of std::ios_base::failure.

Rationale: More detailed error messages.

Effect on original feature: std::ios_base::failure is no longer derived directly from std::exception, but is now derived from std::system_error, which in turn is derived from std::runtime_error. Valid C++ 2003 code that assumes that std::ios_base::failure is derived directly from std::exception may execute differently in this revision of C++.

この変更は、std::ios_base::failureの基底クラスが変更されたことを示しています。これは、より詳細なエラーメッセージを提供するためのものです。std::ios_base::failureはもはやstd::exceptionから直接派生せず、代わりにstd::system_errorから派生し、さらにそれがstd::runtime_errorから派生します。std::ios_base::failurestd::exceptionから直接派生すると仮定している有効なC++ 2003コードは、この改訂版のC++では異なる方法で実行される可能性があります。

C.6 C++ and ISO C[編集]

C.6.1 General[編集]

Subclause C.6 lists the differences between C++ and ISO C, in addition to those listed above, by the chapters of this document.

この節では、C++とISO Cの違いが章ごとにまとめられています。これにより、C++がISO Cと異なる点が明示されています。

C.6.2 Clause 5: lexical conventions[編集]

Affected subclause: 5.11

Change: New Keywords

New keywords are added to C++; see 5.11.

Rationale: These keywords were added in order to implement the new semantics of C++.

C++には新しいキーワードが追加されています。これはC++の新しいセマンティクスを実装するために行われました。

Affected subclause: 5.13.3

Change: Type of character-literal is changed from int to char.

Rationale: This is needed for improved overloaded function argument type matching.

文字リテラルの型がintからcharに変更されました。これは、オーバーロードされた関数の引数の型一致を改善するために必要でした。

Affected subclause: 5.13.5

Change: Concatenated string-literals can no longer have conflicting encoding-prefixes.

Rationale: Removal of non-portable feature.

連結された文字列リテラルは、もはや競合するエンコーディングプレフィックスを持つことができません。これは非ポータブルな機能の削除です。

Affected subclause: 5.13.5

Change: String literals made const.

Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.

文字列リテラルは定数となりました。これは、適切でないオーバーロードされた関数を呼び出すのを避けるためです。その関数は引数を変更できると期待されるかもしれませんが、そうではありません。

C.6.3 Clause 6: basics[編集]

Affected subclause: 6.2

Change: C++ does not have “tentative definitions” as in C.

Rationale: This avoids having different initialization rules for fundamental types and user-defined types

C++には、Cのような「不確定な定義」はありません。これにより、基本型とユーザー定義型の初期化ルールが異なることを避けることができます。

Affected subclause: 6.4

Change: A struct is a scope in C++, not in C.

Rationale: Class scope is crucial to C++, and a struct is a class.

C++では、structはスコープですが、Cではそうではありません。これは、クラスのスコープがC++にとって重要であり、structがクラスであるためです。

Affected subclause: 6.6 [also 9.2.9]

Change: A name of file scope that is explicitly declared const, and not explicitly declared extern, has internal linkage, while in C it would have external linkage.

Rationale: Because const objects may be used as values during translation in C++, this feature urges programmers to provide an explicit initializer for each const object.

ファイルスコープで明示的にconstで宣言され、externでない名前は、C++では内部リンケージを持ちますが、Cでは外部リンケージを持ちます。これは、C++ではconstオブジェクトが翻訳中に値として使用される可能性があるため、プログラマーに対してそれぞれのconstオブジェクトに明示的な初期化子を提供するよう促すためです。

Affected subclause: 6.9.3.1

Change: The main function cannot be called recursively and cannot have its address taken.

Rationale: The main function may require special actions.

main関数は再帰的に呼び出すことができず、アドレスを取ることができません