【发布时间】:2019-04-27 07:38:23
【问题描述】:
提供以下代码,在全局范围内,clang-tidy 不会给出警告:
auto test = []{};
但是,当执行以下操作时,它会:
#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) ^
将 lambda 标记为 noexcept 没有帮助。
但是,我不明白为什么会有问题。理论上,只有在调用 lambda 时才会发生异常,不是吗?
以下代码不会导致出现警告:
auto test = [] {
throw 0;
};
clang-tidy 是不是错了,还是我错过了什么?
【问题讨论】:
标签: c++ lambda clang-tidy