diff options
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/pt.c | 31 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/array2.C | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/dependent-name3.C | 17 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/dependent-name4.C | 15 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/sfinae2.C | 17 |
7 files changed, 97 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a270fba..2d82433 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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* diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1efd808..0490fd1 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 722318f..093e294 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 diff --git a/gcc/testsuite/g++.dg/ext/array2.C b/gcc/testsuite/g++.dg/ext/array2.C new file mode 100644 index 0000000..2d645ca --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/array2.C @@ -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; diff --git a/gcc/testsuite/g++.dg/template/dependent-name3.C b/gcc/testsuite/g++.dg/template/dependent-name3.C new file mode 100644 index 0000000..bbe6fb6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/dependent-name3.C @@ -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; diff --git a/gcc/testsuite/g++.dg/template/dependent-name4.C b/gcc/testsuite/g++.dg/template/dependent-name4.C new file mode 100644 index 0000000..b2b5814 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/dependent-name4.C @@ -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>(); +} diff --git a/gcc/testsuite/g++.dg/template/sfinae2.C b/gcc/testsuite/g++.dg/template/sfinae2.C new file mode 100644 index 0000000..89880a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/sfinae2.C @@ -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" } +} + |