We have observed a strange behaviour in the compilation of the follwing source code:
template<template<class> class TT> struct X { };
template<class> struct Y { };
template<class T> using Z = Y<T>;
int main() {
X<Y> y;
X<Z> z;
z = y; // it fails here
}
This is a slightly modified example taken from the c++11 standard proposal for template aliases: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf (See page 4) Also note that the proposal "declares y and z to be of the same type." In our interpretation it should therefore be possible to assign (or copy construct) z from y.
However, this code doesn't compile with gcc 4.8.1 nor with clang 3.3. Is this an error in the compiler or did we misunderstand the standard?
Thanks in advance, craffael et al ;)
P.S. The Clang error message is:
error: no viable overloaded '='
note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'X<template Y>' to 'const X<template Z>' for 1st argument
template<template<class> class TT> struct X { };
note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'X<template Y>' to 'X<template Z>' for 1st argument
template<template<class> class TT> struct X { };
Y
andZ
are different template-names, as such they yield different instantiations withX
. See §14.5.7/1. – Ligialignaloes