这是关于<;概念>;c+中的lib+;? 我在学习C++中的概念库时遇到了一个“内部编译器错误”…p>

这是关于<;概念>;c+中的lib+;? 我在学习C++中的概念库时遇到了一个“内部编译器错误”…p>,c++,c++-concepts,C++,C++ Concepts,环境: 编译cmd:g++-std=c++17 test.cpp-fconcepts-g-v|更多 一些编译输出: Thread model: posix gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) COLLECT_GCC_OPTIONS='-std=c++17' '-fconcepts' '-g' '-v' '-save-temps' '- shared-libgcc' '-mtune=core2

环境:

编译cmd:
g++-std=c++17 test.cpp-fconcepts-g-v|更多

一些编译输出:

Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
COLLECT_GCC_OPTIONS='-std=c++17' '-fconcepts' '-g' '-v' '-save-temps' '- 
shared-libgcc' '-mtune=core2' '-march=nocona'
我的代码:

template<class A, class B>
concept bool Test = true;

template<class T>
concept bool Ohh = requires(T t, Test<typename T::type> sth){
    { t.func(sth) };
};

//this one works well !!
// template<class T>
// concept bool OK = requires(T t){
//  { t.func(Test<typename T::type>) };
// };

template<class T>
struct A{
    typedef T type;

    void func(T){}
};

Ohh{T} /* OK{T} works fine */
struct B{
    static const bool value = true;
};

int main(int argc, char *argv[] /*, char *envp[]*/)
{
    cout << B<A<int>>::value;
}
模板
概念布尔检验=真;
模板
概念bool Ohh=需要(测试某物){
{t.func(某物)};
};
//这个很好用!!
//模板
//概念布尔OK=需要(T){
//{t.func(Test)};
// };
模板
结构A{
T型;
void func(T){}
};
Ohh{T}/*OK{T}工作正常*/
结构B{
静态常量布尔值=真;
};
int main(int argc,char*argv[]/*,char*envp[]*/)
{

cout任何内部编译器错误都是事实上的编译器错误。问题是,如果编译器工作正常,您的代码是否有效

没有

Test
是一个
constepr
布尔变量,它最终归结为值
true
。变量在
表达式的参数中不是合法的类型名

参数中需要的只是
typename T::type
,因为这是您想要给出的
sth
类型。但您还需要将此概念限制为具有
:type
typename成员的
T

基本上,您不需要
测试

template<class T>
    requires requires { T::type; }
concept bool Ohh = requires(T t, typename T::type sth){
    { t.func(sth) };
};

我认为你陷入了概念前思维的陷阱,你试图使用通常的模板元编程解决方案而不是概念方案。尽可能直接地表达你想要的需求。

我认为任何时候编译器因内部编译器错误而崩溃都是一个bug。但如果它这样做,那只是一个严重的bug编译有效的代码。这显然是一个编译器错误。我用gcc 9.1.1复制了它,因为你不能提交错误报告,出于所述的原因,我为你做了。
template<class T>
    requires requires { T::type; }
concept bool Ohh = requires(T t, typename T::type sth){
    { t.func(sth) };
};
template<class T>
concept bool HasType = requires { T::type; };

template<HasType T>
concept bool Ohh = requires(T t, typename T::type sth){
    { t.func(sth) };
};