Templates 在g++;但不是visualc++;

Templates 在g++;但不是visualc++;,templates,visual-c++,compiler-errors,Templates,Visual C++,Compiler Errors,以下编译为G++,但不在VisualC++中(VisualStudio Express 2012)编译。为什么? 如果我使用非int(比如说,double)的类型调用foo,那么我希望这会中断,因为在这种情况下B::bbb:aaa是没有意义的。但是如果我只想用类型int调用foo,那么它应该可以工作。事实上,在VC++中编译失败,即使我根本不调用foo struct A { typedef int aaa; }; template <typename T> struct B

以下编译为G++,但不在VisualC++中(VisualStudio Express 2012)编译。为什么?

如果我使用非
int
(比如说,
double
)的类型调用
foo
,那么我希望这会中断,因为在这种情况下
B::bbb:aaa
是没有意义的。但是如果我只想用类型
int
调用
foo
,那么它应该可以工作。事实上,在VC++中编译失败,即使我根本不调用
foo

struct A {
    typedef int aaa;
};

template <typename T>
struct B {
    typedef void bbb;
};

template <>
struct B<int> {
    typedef A bbb;
};

template <typename T>
typename B<T>::bbb::aaa // line 16
foo(const T &arg) {     // line 17
    return typename B<T>::bbb::aaa();
}

int main() {
    // Compilation fails with or without the following two lines.
    //int x = 0;
    //foo(x);
}

我相信这是VisualC++中的一个bug。我看代码没有任何问题。您可以通过使用
标题中的
common\u-type
将返回类型更改为
typename std::common\u-type::type::aaa>来解决此问题。请考虑打开bug。谢谢。我已经提交了一份bug报告:
gcc_vs_vs.cc(16) : error C2510: 'bbb' : left of '::' must be a class/struct/union
gcc_vs_vs.cc(17) : error C2146: syntax error : missing ';' before identifier 'foo'
gcc_vs_vs.cc(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
gcc_vs_vs.cc(17) : error C2143: syntax error : missing ',' before '&'