Namespaces
Variants

C++ attribute: indeterminate (since C++26)

From cppreference.net
C++ language
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
constexpr (C++11)
consteval (C++20)
constinit (C++20)
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
Attributes
(C++23)
(C++11) (until C++26)
(C++14)
indeterminate
(C++26)
(C++20)
(C++17)
(C++11)
(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 Indeterminate storage [dcl.attr.indet]