This is the mail archive of the
mailing list for the GCC project.
[RFC] c++ template instantiation generates zero-sized array (pr 19989)
- From: Josh Conner <jconner at apple dot com>
- To: gcc at gcc dot gnu dot org
- Cc: Mark Mitchell <mark at codesourcery dot com>, Jason Merrill <jason at redhat dot com>, Nathan Sidwell <nathan at codesourcery dot com>
- Date: Tue, 01 Nov 2005 08:52:46 -0800
- Subject: [RFC] c++ template instantiation generates zero-sized array (pr 19989)
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
This is rejected on the grounds that not failing could generate an
incorrect match in other instances, e.g.:
template<int M> void foobar (int (*) [M] = 0 );
template<int M> void foobar ( );
void fn (void)
Where we are required to match the second form of foobar.
Before I propose a patch for this behavior, however, I'd like to
understand the most desirable behavior (understanding that
implementation complexity may limit what is possible in the short term).
For my first example (the class template), I believe gcc should in an
* by default: accept it with no warnings/errors
* with -pedantic: generate an error
* with -pedantic -fpermissive: generate a warning
For the second example (the function template), I believe gcc should:
* by default: bind to the second foobar
* with -fpermissive: bind to the first foobar (which will generate a
duplicate matching template error)
* with -fpermissive -pedantic: bind to the first foobar, with a
warning (also generating a duplicate matching template error)
Is this an accurate summary of what we'd like to see?