C++ attribute: indeterminate (since C++26)
| General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
|
||||||||||||||||
| Jump statements | ||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
inline
specifier
|
||||||||||||||||
| Dynamic exception specifications ( until C++17* ) | ||||||||||||||||
noexcept
specifier
(C++11)
|
||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
|
||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean - Integer - Floating-point | ||||||||||||||||
| Character - String - nullptr (C++11) | ||||||||||||||||
| User-defined (C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes (C++11) | ||||||||||||||||
| Types | ||||||||||||||||
typedef
declaration
|
||||||||||||||||
| Type alias declaration (C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
|
||||||||||||||||
| Special member functions | ||||||||||||||||
|
||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++23)
|
||||
|
(C++11)
(until C++26)
|
||||
|
(C++14)
|
||||
|
(C++17)
|
||||
|
indeterminate
(C++26)
|
||||
|
(C++20)
|
||||
|
(C++17)
|
||||
|
(C++17)
|
||||
|
(C++11)
|
||||
|
(C++20)
|
||||
|
(TM TS)
|
||||
|
(C++20)
|
変数または関数パラメータが初期化されていない場合、不定値を持つことを示します。
目次 |
構文
[
[
indeterminate
]
]
|
|||||||||
説明
[[
indeterminate
]]
は、自動
storage duration
を持つブロック変数の定義、または
function declaration
のパラメータ宣言に適用できます。この属性は、自動ストレージ期間を持つオブジェクトのストレージを構成するバイトが、初期状態で誤った値ではなく
indeterminate
であることを指定します。
関数のパラメータが
[[
indeterminate
]]
で宣言されている場合、その関数の最初の宣言で宣言されなければなりません。ある翻訳単位で関数の最初の宣言においてパラメータが
[[
indeterminate
]]
で宣言され、別の翻訳単位で同じ関数の最初の宣言において同じパラメータが
[[
indeterminate
]]
なしで宣言されている場合、そのプログラムは
不適格であり、診断は不要
です。
注記
[[indeterminate]]
属性は、C++26まで暗黙的に導入されていた未定義動作を復元します。これにより、コンパイラが不定値を読み取るコードパスを到達不能と判断する可能性があります。
例
void f(int); void g() { int x [[indeterminate]]; // 不定値 int y; // 誤った値 f(x); // 未定義動作 f(y); // 誤った動作 } struct T { T() {} int x; }; void h(T a [[indeterminate]], T b) { f(a.x); // 下記呼び出し時に未定義動作 f(b.x); // 下記呼び出し時に誤った動作 } h(T(), T());
参考文献
- C++26規格 (ISO/IEC 14882:2026):
-
- 9.12.7 不定ストレージ [dcl.attr.indet]