This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why is this still not allowed by gcc while MSVC does(const template argument)


"Jun Chen" <chjfth@gmail.com> writes:

> Please check the following small program:

This is the wrong mailing list.  Please use gcc-help@gcc.gnu.org for
questions about using gcc.  The mailing list gcc@gcc.gnu.org is for
developers of gcc itself.  Please take any followups to
gcc-help@gcc.gnu.org.  Thanks.


> {code}
> t1.cpp:56: error: could not convert template argument '0' to 'MyClass*'
> t1.cpp:56: error: invalid type in declaration before ';' token
> t1.cpp: In function 'int main()':
> t1.cpp:63: error: invalid types 'CecMyClass[int]' for array subscript
> t1.cpp:64: error: invalid types 'CecMyClass[int]' for array subscript
> {code}
> 
> I'm really baffled! Since 0 can be assigned to any pointer variable,
> then why "0 could not be converted to MyClass* "?

The C++ standard is clear: "Although 0 is a valid template-argument
for a non-type template-parameter of integral type, it is not a valid
template-argument for a non-type template-parameter of pointer type."
(14.3.2 Template non-type arguments [temp.arg.nontype]).

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]