Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Potentially empty optional 'variable' is unwrapped, may throw exception
Remarks
Unwrapping empty std::optional values via the value method will throw an exception. Such operation can result in a crash when the exception isn't handled. This check will attempt to find cases where a std::optional isn't checked for emptiness before unwrapping it via the value method. You can enable C26829, and C26859 only for a more permissive analysis.
Example
std::optional<int> getOptional();
void f(std::optional<int> maybeEmpty)
{
if (maybeEmpty)
maybeEmpty.value() = 42; // No warning
maybeEmpty.value() = 5; // warning: C26860
std::optional<int> o = getOptional();
o.value() = 42; // warning: C26860
}
To solve this problem, make sure the code never unwraps an empty optional.