This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] c++ template instantiation generates zero-sized array (pr19989)
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Josh Conner <jconner at apple dot com>
- Cc: gcc at gcc dot gnu dot org, Jason Merrill <jason at redhat dot com>, Nathan Sidwell <nathan at codesourcery dot com>
- Date: Tue, 01 Nov 2005 17:12:23 -0800
- Subject: Re: [RFC] c++ template instantiation generates zero-sized array (pr19989)
- References: <43679D5E.5080300@apple.com>
Josh Conner wrote:
> I've been investigating PR 19989, where we are rejecting code when a
> template instantiation generates a zero-sized array, such as:
>
> template<int> struct A
> {
> static const int i = 0;
> }
>
> template<int N> struct B
> {
> int x[A<N>::i];
> };
>
> B<0> b;
>
> This is rejected on the grounds that not failing could generate an
> incorrect match in other instances
I understand what you're after: tolerate uses of the extension where
it's sufficiently harmless.
I don't think your proposed solution is correct, though, because we want
to maintain the invariant that all conforming programs compile and
behave as required by the standard in all compilation modes. In other
words, supplying -fpermissive and friends can make non-conforming
programs compile, when they otherwise wouldn't, but conforming programs
should behave identically in all modes.
I would imagine that if we encounter a zero-sized array when the
"complain" flag is tf_error, then we can just issue a conditional
pedwarn, with "if (pedantic) pedwarn (...)". But, if tf_error is not
set, we must reject the instantiation.
I know that sounds backwards. The point is that when tf_error is set,
we're committed to the instantiation. When tf_error is not set, SFINAE
applies. And, in a conforming program, we must reject the instantiation
in that case.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304