Questions tagged «static-assert»



2
如果constexpr在lambda中带有static_assert,哪个编译器正确?
当我们要在中使用时static_assert,if constexpr必须使条件取决于某些模板参数。有趣的是,当代码包装在lambda中时,gcc和clang不同意。 以下代码使用gcc进行编译,但是clang触发断言,即使if constexpr不能为true。 #include <utility> template<typename T> constexpr std::false_type False; template<typename T> void foo() { auto f = [](auto x) { constexpr int val = decltype(x)::value; if constexpr(val < 0) { static_assert(False<T>, "AAA"); } }; f(std::integral_constant<int, 1>{}); } int main() { foo<int>(); } 这里的例子。 它可以很容易地通过用固定False<T>通过False<decltype(x)>。 所以问题是:哪个编译器正确?我认为gcc是正确的,因为中的条件static_assert取决于T,但是我不确定。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.