Provided the following code, in the global scope, clang-tidy gives no warning:
auto test = []{};
However, when doing the following, it does:
#include <tuple>
auto test = []{
std::tuple t{1, 2, 3};
};
<source>:3:6: warning: initialization of 'test' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp] auto test = []{ ^ /opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/tuple:646:19: note: possibly throwing constructor declared here constexpr tuple(_UElements&&... __elements) ^
Marking the lambda as noexcept
doesn't help.
However, I don't see why that would be a problem. The exception could only theorically happen when invoking the lambda, wouldn't it?
The following code does not cause the warning to appear:
auto test = [] {
throw 0;
};
Is clang-tidy wrong, or did I miss something?