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, e.g.:

  template<int M> void foobar (int (*) [M] = 0 );
  template<int M> void foobar ( );

  void fn (void)
  {
    foobar<0>();
  }

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
ideal world:

  * 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?

Thanks -

Josh

Reply via email to