GCC 4.8 的最新版本在头文件中提供了以下代码:
auto L = [](){};
struct S
{
decltype(L) m;
};
以下警告:
test.hpp:3:8: warning: 'S' has a field 'S::m' whose type uses the anonymous namespace [enabled by default]
struct S
^
为什么编译器会考虑 lambda 的类型来使用匿名命名空间?我将 lambda 设为全局,我没有在任何地方使用匿名命名空间。
更新:即使我将 lambda 放在显式命名空间中,编译也会给出相同的警告,如下所示:
namespace N
{
auto L = [](){};
}
struct S
{
decltype(N::L) m;
};
更新 2:事实上,似乎甚至类范围 lambdas 也有同样的问题:
class N
{
static constexpr auto L = [](){};
};
struct S
{
decltype(N::L) m;
};