mirror of git://gcc.gnu.org/git/gcc.git
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:
parent
a63607ed43
commit
95cd6f6f66
|
@ -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>
|
2005-11-04 Joseph S. Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
* cp-tree.h (cp_cpp_error), error.c (cp_cpp_error): Take va_list*
|
* cp-tree.h (cp_cpp_error), error.c (cp_cpp_error): Take va_list*
|
||||||
|
|
21
gcc/cp/pt.c
21
gcc/cp/pt.c
|
@ -7083,16 +7083,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
|
||||||
max = tsubst_template_arg (omax, args, complain, in_decl);
|
max = tsubst_template_arg (omax, args, complain, in_decl);
|
||||||
max = fold_decl_constant_value (max);
|
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
|
Type deduction may fail for any of the following
|
||||||
|
@ -7100,8 +7090,17 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
|
||||||
|
|
||||||
Attempting to create an array with a size that is
|
Attempting to create an array with a size that is
|
||||||
zero or negative. */
|
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)
|
if (complain & tf_error)
|
||||||
error ("creating array with size zero (%qE)", max);
|
error ("creating array with negative size (%qE)", max);
|
||||||
|
|
||||||
return error_mark_node;
|
return error_mark_node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
|
||||||
|
|
||||||
PR preprocessor/22042
|
PR preprocessor/22042
|
||||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -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>();
|
||||||
|
}
|
|
@ -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" }
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue