llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.22k stars 11.16k forks source link

bugprone-unchecked-optional-access false positive #86185

Open alexolog opened 4 months ago

alexolog commented 4 months ago

Code:

    if (auto error = checkMsg(msg, fieldMask, {}); error.has_value())
        throw std::runtime_error(*error);

Diagnostic:

protobuf_validation.h:69:35: warning: unchecked access to optional value [bugprone-unchecked-optional-access]
   69 |         throw std::runtime_error(*error);
      |                                   ^

LLVM 17.0.6 on Mac.

llvmbot commented 4 months ago

@llvm/issue-subscribers-clang-tidy

Author: Alex (alexolog)

Code: ``` if (auto error = checkMsg(msg, fieldMask, {}); error.has_value()) throw std::runtime_error(*error); ``` Diagnostic: ``` protobuf_validation.h:69:35: warning: unchecked access to optional value [bugprone-unchecked-optional-access] 69 | throw std::runtime_error(*error); | ^ ``` LLVM 17.0.6 on Mac.
EugeneZelenko commented 4 months ago

Could you please try 18 or main branch?

alexolog commented 4 months ago

Could you please try 18 or main branch?

As soon as it gets on homebrew :)

chrchr-github commented 4 months ago

Does not immediately repro with trunk: https://godbolt.org/z/qobYKv1zn