Question

When I declare a template method of a template class whose argument type is specified by a template alias, I get a compile error. If I change the template class to a class, it compiles. If I replace the template alias by the actual type (here Templ<bool>), it compiles, too. Why doesn't it work, when it is a template class and the argument type is a template alias?

The compiler is gcc version 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>;
Was it helpful?

Solution

This seems to be regression in gcc 4.8.0 because gcc 4.7.2 does compile both versions without errors. The Standard 14.1/2 specifically states that

There is no semantic difference between class and typename in a template-parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top