+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*
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;
}
+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
--- /dev/null
+// { 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;
--- /dev/null
+// { 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;
--- /dev/null
+// { 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>();
+}
--- /dev/null
+// 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" }
+}
+