g ++和clang ++使用使用别名定义方法的不同行为

max*_*x66 5 c++ templates using c++11

尝试回答另一个问题,我发现g ++和clang ++对以下简单代码有不同意见

template <typename>
struct foo
 { void bar (); };

template <typename T>
using fooAlias = foo<T>;

template <typename T>
void fooAlias<T>::bar ()
 { }

int main ()
 {
 }
Run Code Online (Sandbox Code Playgroud)

当clang ++编译时,g ++给出以下错误

tmp_003-14,gcc,clang.cpp:26:24: error: invalid use of incomplete type ‘struct foo<T>’
 void fooAlias<T>::bar ()
                        ^
tmp_003-14,gcc,clang.cpp:19:8: note: declaration of ‘struct foo<T>’
 struct foo
        ^~~
Run Code Online (Sandbox Code Playgroud)

与往常一样,问题是:谁是对的?lang ++或g ++?

我还观察到分歧与模板参数的存在有关。

确实clang ++和g ++都编译以下代码

struct foo
 { void bar (); };

using fooAlias = foo;

void fooAlias::bar ()
 { }

int main ()
 {
 }
Run Code Online (Sandbox Code Playgroud)