Mark Mitchell - Re: [RFC] c++ template instantiation generates zero-sized array (pr19989 (original) (raw)

This is the mail archive of the gcc@gcc.gnu.orgmailing 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]

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 struct A { static const int i = 0; }

template struct B { int x[A::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


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