小编123*_*3tv的帖子

模板类中结构的 C++ 编译器问题

以下代码不能用 gcc 或 clang 编译。

template<class T>
class foo{};

template<class T>
class template_class_with_struct
{
    void my_method() {
        if(this->b.foo < 1);
    };

    struct bar
    {
        long foo;
    } b;
};
Run Code Online (Sandbox Code Playgroud)

错误信息是

error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class foo'    
    8 |         if(this->b.foo < 1);
Run Code Online (Sandbox Code Playgroud)

该错误是由模板类 foo 引起的。当编写 <= 而不是 < 1 时,它也会编译。

任何提示赞赏?

CompilerExplorer 链接https://godbolt.org/z/v6Tygo

c++ templates compiler-errors compiler-bug

13
推荐指数
1
解决办法
171
查看次数

标签 统计

c++ ×1

compiler-bug ×1

compiler-errors ×1

templates ×1