代码之家  ›  专栏  ›  技术社区  ›  Julius

带括号的“嵌套”类模板参数推导:gcc与clang

  •  4
  • Julius  · 技术社区  · 6 年前

    相关,但(imho)不同: Nested template argument deduction for class templates not working

    下面的C++ 17代码从GCC 8中被拒绝,但是CLAN编译它没有任何问题。GCC的错误消息作为注释包含在有问题的行之前。

    这里哪个编译器是正确的?

    https://godbolt.org/z/WG6f7G

    template<class T>
    struct Foo {
        Foo(T) {}
    };
    
    template<class T>
    struct Bar {
         Bar(T) {};
    };
    
    void works() {
        Bar bar{1};// {}
        Foo foo(bar);// ()
    }
    
    void works_too() {
        Foo foo{Bar{1}};// {{}}
    }
    
    void error_in_gcc() {
    // error: 'auto' parameter not permitted in this context
        Foo foo(Bar{1});// ({})
    }
    
    void but_this_works() {
        Foo(Bar{1});// ({})
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •       6 年前

    对这个问题的评论指出这是一个gcc错误。已作为GCC Bug报告归档。 89062 .