On Tue, 8 Nov 2011, Marc Glisse wrote:
On Tue, 8 Nov 2011, Ulrich Drepper wrote:
Complicated title, here's a bit of code:
#ifdef FIX
# define PARM2 , class T5
#else
# define PARMS2
#endif
template<typename T1, typename T2 = int>
struct cl1 {
};
template<template<class T3 PARM2> class T4 = cl1>
struct cl2 {
};
cl2<> var;
If compiled without FIX defined this will fail with gcc 4.3 and later.
Haven't checked 4.2 but it works without the fix with gcc 4.1. The
strange thing is that it also worked with ancient compilers before the
C++ frontend rewrite (gcc 3.2). In short, when a expecting a template
class in a template parameter list it now is not possible anymore to
skip the default parameters. Since this is an actual use of the class
(in case the default is used) and the programmer declares to have no
interest in the type of the second template parameter I wouldn't say
it is needed but I haven't tracked a statement in the standard.
Before changing too much code I want to make sure this new and very
old behavior is what is required by the standard and not a bug which
slipped in again.
It is announced in:
http://gcc.gnu.org/gcc-4.2/changes.html
It broke quite a bit of code (in particular with std::vector as cl1), but
there were some exotic pieces of legal code that were broken by this
extension, so it had to go.
Notice that in C++11 mode, g++ accepts:
#include <vector>
template <template<class...>class V> struct A {
typedef V<double> T;
};
int main(){
A<std::vector>::T t;
}
where it matches vector as V having 2 parameters but lets you use it with
one. Don't know if you can rely on it though.
--
Marc Glisse