我已经研究有状态元编程有一段时间了。
我在 GCC 中发现了一个奇怪的行为
#include <type_traits>
//removing template will make it compile
template <typename = void>
void test() {
// Replacing lambda with any other type will make it compile as well
using NonDependentStaticType = decltype([](){});
static_assert(std::is_same_v<NonDependentStaticType, NonDependentStaticType>);
}
int main() {
test();
}
此代码可以针对最新的 clang 和 MSVC 进行编译,但无法针对 GCC 进行编译。
无论编译器如何处理默认的 lambda 模板参数,
static_assert
都一定不会失败,我是否正确?
更新:感谢@Jarod42提供简化的代码示例
无论编译器如何处理默认的 lambda 模板参数,
都一定不会失败,我是否正确?static_assert
是的。这是 gcc 中的一个错误(我为此编写了 116714),现在已针对 gcc 15 进行了修复,因为您可以通过重新运行使用 gcc trunk 的实时示例来验证自己。