I’ve encountered cert-err58-cpp
firing on the following reduced code snippet:
// main.cpp
struct callbacks {
void (*cb)();
};
void foo() {}
const auto g_cbs = callbacks{[]() { foo(); }};
const auto g_cb = []() { foo(); };
int main() { return 0; }
Run: clang-tidy main.cpp "-checks=-*,cert-err58-cpp" --
, note how it fires for g_cbs
and not for g_cb
:
1 warning generated.
/home/itay/tmp/err58/main.cpp:7:12: warning: initialization of 'g_cbs' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
const auto g_cbs = callbacks{[]() { foo(); }};
^
/home/itay/tmp/err58/main.cpp:5:6: note: possibly throwing function declared here
void foo() {}
^
Would that be considered a bug?