使用variadic概念模板时GCC内部错误
gcc internal error when using variadic concept template
i最近在gcc
中使用了概念功能,并在类的构造函数或类的构造函数中使用variadic概念模板时偶然发现了此错误:
template<typename From, typename To>
concept bool ConvertibleNoNarrow = requires(From f, To t) {
t = { f };
};
class Foo
{
public:
template<ConvertibleNoNarrow<double>... Args>
Foo(Args&&... args) { /*...*/ }
};
使用Foo
时,GCC显示一个内部错误:
err.cpp: In substitution of ‘template<class ... Args> requires ConvertibleNoNarrow<Args, double>... Foo::Foo(Args&& ...) [with Args = {double}]’: err.cpp:23:11: required from here err.cpp:13:3: internal compiler error: in tsubst_constraint, at cp/constraint.cc:1956 Foo(Args&&... args) { } ^~~
如果在全局功能中使用了相同的签名,则一切都按预期工作:
/* works */
template<ConvertibleNoNarrow<double>... Args>
void Test(Args&&... args) { }
任何人都可以复制此事或有头绪,为什么会发生这种情况以及如何调用现有的错误报告?
编辑:
我的GCC版本:
gcc (Gentoo 7.2.0 p1.1) 7.2.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
这是GCC(Bugzilla链接)中的一个错误。
但是,您可以通过在requires
子句中添加约束来解决问题。因此,我们在每种类型上检查概念,并相应地返回std::true_type
或std::false_type
。通过这样做,我们可以将std::conjunction_v
与参数包扩展一起使用以独立约束。
class Foo
{
public:
template<typename... Args>
requires std::conjunction_v<std::conditional_t
< ConvertibleNoNarrow<Args, double>
, std::true_type
, std::false_type
>...>
Foo(Args&&... args) { /*...*/ }
};
类似于 @nyronium的答案,但是更简单,您可以在"需求"子句中使用折叠表达式。
class Foo
{
public:
template<typename... Args>
requires (ConvertibleNoNarrow<Args, double> && ...)
Foo(Args&&... args) { /*...*/ }
};
我在GCC 7.3.0上测试了等效物。
相关文章:
- 将函数类成员映射到类本身内部
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 奇怪的结构&GCC&clang(void*返回类型)
- GCC本机矩阵运算库
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- Boost Spirit,获取迭代器内部语义动作
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 防止gcc破坏我的AVX2内部复制到REP MOVS
- GCC(通过 CUDA)内部函数的编译器错误,但我没有使用任何
- 使用variadic概念模板时GCC内部错误
- gcc 4.7.3与构造函数一起使用make_shared时出现内部编译器错误
- GCC 3.4 内部编译器错误与 std::map.find
- 为什么 GCC 的 std::function 不使用对按值传递的参数的右值引用来在其内部委托之间传递它们?
- GCC内部符号装饰有什么问题
- 内部编译错误:分割错误在gcc.发送可变模板到struct时