4

当我声明参数类型由模板别名指定的模板类的模板方法时,出现编译错误。如果我将模板类更改为一个类,它会编译。如果我用实际类型(此处)替换模板别名Templ<bool>,它也会编译。当它是模板类并且参数类型是模板别名时,为什么它不起作用?

编译器是 gcc 版本 4.8.0 (Ubuntu/Linaro 4.8.0-2ubuntu2~12.04)。

template <template <typename T> class Templ>
using Bool = Templ<bool>;

template <typename T>
class Foo {
private:
public:
    template<template<typename U> class Templ>
    void method(Bool<Templ> boolTempl);
};

template <typename T>
template <template <typename U> class Templ>
void Foo<T>::method(Bool<Templ> boolTempl) {
}

int main() {
    Foo<char> foo;
    return 0;
}

g++ templTest12.C -o templTest12 -std=c++11
templTest12.C: In substitution of `template<template<class T> class Templ> using Bool = Templ<bool> [with Templ = Templ]':
templTest12.C:17:6:   required from `class Foo<char>'
templTest12.C:30:12:   required from here
templTest12.C:2:25: error: `template<class U> class Templ' is not a template
 using Bool = Templ<bool>;
4

1 回答 1

3

这似乎是 gcc 4.8.0 中的回归,因为 gcc 4.7.2 确实编译了两个版本而没有错误。标准 14.1/2 明确指出

模板参数中的类和类型名之间没有语义差异。

于 2013-05-08T11:40:59.857 回答