re PR c++/19989 (Inconsistency with zero-sized arrays)

PR c++/19989
cp/pt.c (tsubst): Accept zero-length array if tf_error is set
in complain flags.  Change error message for negative-
length array.
testsuite/g++.dg/ext/array2.C: New test.
testsuite/g++.dg/template/dependent-name3.C: New test.
testsuite/g++.dg/template/dependent-name4.C: New test.
testsuite/g++.dg/template/sfinae2.C: New test.

From-SVN: r106468
This commit is contained in:
Josh Conner 2005-11-04 01:23:22 +00:00 committed by Josh Conner
parent a63607ed43
commit 95cd6f6f66
7 changed files with 97 additions and 16 deletions

View File

@ -1,3 +1,10 @@
2005-11-03 Josh Conner <jconner@apple.com>
PR c++/19989
pt.c (tsubst): Accept zero-length array if tf_error is set
in complain flags. Change error message for negative-
length array.
2005-11-04 Joseph S. Myers <joseph@codesourcery.com>
* cp-tree.h (cp_cpp_error), error.c (cp_cpp_error): Take va_list*

View File

@ -7083,25 +7083,24 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
max = tsubst_template_arg (omax, args, complain, in_decl);
max = fold_decl_constant_value (max);
if (integer_zerop (omax))
{
/* Still allow an explicit array of size zero. */
if (pedantic)
pedwarn ("creating array with size zero");
}
else if (integer_zerop (max)
|| (TREE_CODE (max) == INTEGER_CST
&& INT_CST_LT (max, integer_zero_node)))
{
/* [temp.deduct]
/* [temp.deduct]
Type deduction may fail for any of the following
reasons:
Type deduction may fail for any of the following
reasons:
Attempting to create an array with a size that is
zero or negative. */
Attempting to create an array with a size that is
zero or negative. */
if (integer_zerop (max) && !(complain & tf_error))
/* We must fail if performing argument deduction (as
indicated by the state of complain), so that
another substitution can be found. */
return error_mark_node;
else if (TREE_CODE (max) == INTEGER_CST
&& INT_CST_LT (max, integer_zero_node))
{
if (complain & tf_error)
error ("creating array with size zero (%qE)", max);
error ("creating array with negative size (%qE)", max);
return error_mark_node;
}

View File

@ -1,3 +1,11 @@
2005-11-03 Josh Conner <jconner@apple.com>
PR c++/19989
g++.dg/ext/array2.C: New test.
g++.dg/template/dependent-name3.C: New test.
g++.dg/template/dependent-name4.C: New test.
g++.dg/template/sfinae2.C: New test.
2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
PR preprocessor/22042

View File

@ -0,0 +1,18 @@
// { dg-do compile }
// Avoid -pedantic-error default
// { dg-options "" }
// PR 19989 - dependent array of size 0 fails to compile.
template<int I> struct A
{
static const int zero = 0;
};
template<int N> struct B
{
int x[A<N>::zero];
};
B<0> b;

View File

@ -0,0 +1,17 @@
// { dg-do compile }
// Dependent arrays of invalid size generate appropriate error messages
template<int I> struct A
{
static const int zero = 0;
static const int minus_one = -1;
};
template<int N> struct B
{
int x[A<N>::zero]; // { dg-error "zero" }
int y[A<N>::minus_one]; // { dg-error "negative" }
};
B<0> b;

View File

@ -0,0 +1,15 @@
// { dg-do compile }
// Dependent arrays of invalid size cause template instantiation failure.
// We'll get an error message (duplicate matching templates) if the first
// pattern is incorrectly allowed to match.
template<int M> void foobar (int (*) [M] = 0 );
template<int M> void foobar ( );
void fn (void)
{
foobar<0>();
foobar<-1>();
}

View File

@ -0,0 +1,17 @@
// PR c++/19989
// Don't instantiate a function template if it would generate an
// array of size zero.
// { dg-do compile }
template<int T> struct cl {
const static int value = T;
};
template<int I> void fn (char (*) [cl<I>::value] = 0 );
void foo (void)
{
fn<0> (); // { dg-error "no matching function" }
}