From ed4f2c001a883b2456fc607a33f1c59f9c4ee65d Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 13 Aug 2018 23:12:11 +0000 Subject: [PATCH] re PR c++/57891 (No diagnostic of narrowing conversion in non-type template argument) PR c++/57891 * call.c (struct conversion): Add check_narrowing_const_only. (build_converted_constant_expr): Set check_narrowing and check_narrowing_const_only. Give error if expr is error node. (convert_like_real): Pass it to check_narrowing. * cp-tree.h (check_narrowing): Add a default parameter. * decl.c (compute_array_index_type): Use input_location instead of location_of. * pt.c (convert_nontype_argument): Return NULL_TREE if tf_error. * typeck2.c (check_narrowing): Don't warn for instantiation-dependent expressions. Call maybe_constant_value instead of fold_non_dependent_expr. Don't mention { } in diagnostic. Only check narrowing for constants if CONST_ONLY. * g++.dg/cpp0x/Wnarrowing6.C: New test. * g++.dg/cpp0x/Wnarrowing7.C: New test. * g++.dg/cpp0x/Wnarrowing8.C: New test. * g++.dg/cpp0x/Wnarrowing9.C: New test. * g++.dg/cpp0x/Wnarrowing10.C: New test. * g++.dg/cpp0x/constexpr-47969.C: Adjust dg-error. * g++.dg/cpp0x/constexpr-ex2.C: Likewise. * g++.dg/cpp0x/constexpr-targ.C: Likewise. * g++.dg/cpp0x/scoped_enum2.C: Likewise. * g++.dg/ext/stmtexpr15.C: Likewise. * g++.dg/gomp/pr47963.C: Likewise. * g++.dg/init/new37.C: Likewise. * g++.dg/init/new43.C: Likewise. * g++.dg/other/fold1.C: Likewise. * g++.dg/parse/array-size2.C: Likewise. * g++.dg/template/dependent-name3.C: Likewise. * g++.dg/cpp0x/constexpr-data2.C: Add dg-error. * g++.dg/other/vrp1.C: Likewise. * g++.dg/template/char1.C: Likewise. From-SVN: r263523 --- gcc/cp/ChangeLog | 16 +++++ gcc/cp/call.c | 19 +++++- gcc/cp/cp-tree.h | 3 +- gcc/cp/decl.c | 2 +- gcc/cp/pt.c | 4 +- gcc/cp/typeck2.c | 25 ++++--- gcc/testsuite/ChangeLog | 23 +++++++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing10.C | 5 ++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing6.C | 8 +++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing7.C | 9 +++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing8.C | 6 ++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing9.C | 6 ++ gcc/testsuite/g++.dg/cpp0x/constexpr-47969.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-targ.C | 2 +- gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C | 4 +- gcc/testsuite/g++.dg/ext/stmtexpr15.C | 2 +- gcc/testsuite/g++.dg/gomp/pr47963.C | 2 +- gcc/testsuite/g++.dg/init/new37.C | 2 +- gcc/testsuite/g++.dg/init/new43.C | 66 +++++++++---------- gcc/testsuite/g++.dg/other/fold1.C | 2 +- gcc/testsuite/g++.dg/other/vrp1.C | 2 +- gcc/testsuite/g++.dg/parse/array-size2.C | 2 +- gcc/testsuite/g++.dg/template/char1.C | 3 +- .../g++.dg/template/dependent-name3.C | 2 +- 26 files changed, 159 insertions(+), 62 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing10.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing6.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing7.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing8.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e4984bdb17b..40b384a1e62 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,19 @@ +2018-08-13 Marek Polacek + + PR c++/57891 + * call.c (struct conversion): Add check_narrowing_const_only. + (build_converted_constant_expr): Set check_narrowing and + check_narrowing_const_only. Give error if expr is error node. + (convert_like_real): Pass it to check_narrowing. + * cp-tree.h (check_narrowing): Add a default parameter. + * decl.c (compute_array_index_type): Use input_location instead of + location_of. + * pt.c (convert_nontype_argument): Return NULL_TREE if tf_error. + * typeck2.c (check_narrowing): Don't warn for instantiation-dependent + expressions. Call maybe_constant_value instead of + fold_non_dependent_expr. Don't mention { } in diagnostic. Only check + narrowing for constants if CONST_ONLY. + 2018-08-13 Martin Sebor PR tree-optimization/71625 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 209c1fd2f0e..62654a9e407 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -107,6 +107,9 @@ struct conversion { binding a reference directly or decaying to a pointer. */ BOOL_BITFIELD rvaluedness_matches_p: 1; BOOL_BITFIELD check_narrowing: 1; + /* Whether check_narrowing should only check TREE_CONSTANTs; used + in build_converted_constant_expr. */ + BOOL_BITFIELD check_narrowing_const_only: 1; /* The type of the expression resulting from the conversion. */ tree type; union { @@ -4152,9 +4155,18 @@ build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain) } if (conv) - expr = convert_like (conv, expr, complain); + { + conv->check_narrowing = true; + conv->check_narrowing_const_only = true; + expr = convert_like (conv, expr, complain); + } else - expr = error_mark_node; + { + if (complain & tf_error) + error_at (loc, "could not convert %qE from %qH to %qI", expr, + TREE_TYPE (expr), type); + expr = error_mark_node; + } /* Free all the conversions we allocated. */ obstack_free (&conversion_obstack, p); @@ -7142,7 +7154,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, } if (convs->check_narrowing - && !check_narrowing (totype, expr, complain)) + && !check_narrowing (totype, expr, complain, + convs->check_narrowing_const_only)) return error_mark_node; warning_sentinel w (warn_zero_as_null_pointer_constant); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 94a85b72d2b..9608cf5334b 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7397,7 +7397,8 @@ extern int abstract_virtuals_error_sfinae (abstract_class_use, tree, tsubst_flag extern tree store_init_value (tree, tree, vec**, int); extern tree split_nonconstant_init (tree, tree); -extern bool check_narrowing (tree, tree, tsubst_flags_t); +extern bool check_narrowing (tree, tree, tsubst_flags_t, + bool = false); extern tree digest_init (tree, tree, tsubst_flags_t); extern tree digest_init_flags (tree, tree, int, tsubst_flags_t); extern tree digest_nsdmi_init (tree, tree, tsubst_flags_t); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 97f1cfb792e..9a2e3247946 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9702,7 +9702,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) { tree folded = cp_fully_fold (size); if (TREE_CODE (folded) == INTEGER_CST) - pedwarn (location_of (size), OPT_Wpedantic, + pedwarn (input_location, OPT_Wpedantic, "size of array is not an integral constant-expression"); /* Use the folded result for VLAs, too; it will have resolved SIZEOF_EXPR. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7fcf5d6b2d3..cbb7b8ea853 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6682,7 +6682,9 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) template-parameter. */ expr = build_converted_constant_expr (type, expr, complain); if (expr == error_mark_node) - return error_mark_node; + /* Make sure we return NULL_TREE only if we have really issued + an error, as described above. */ + return (complain & tf_error) ? NULL_TREE : error_mark_node; expr = maybe_constant_value (expr); expr = convert_from_reference (expr); } diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 72515d9ece7..674d08762b5 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -875,10 +875,12 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags) } -/* Give diagnostic about narrowing conversions within { }. */ +/* Give diagnostic about narrowing conversions within { }, or as part of + a converted constant expression. If CONST_ONLY, only check + constants. */ bool -check_narrowing (tree type, tree init, tsubst_flags_t complain) +check_narrowing (tree type, tree init, tsubst_flags_t complain, bool const_only) { tree ftype = unlowered_expr_type (init); bool ok = true; @@ -886,7 +888,9 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) if (((!warn_narrowing || !(complain & tf_warning)) && cxx_dialect == cxx98) - || !ARITHMETIC_TYPE_P (type)) + || !ARITHMETIC_TYPE_P (type) + /* Don't emit bogus warnings with e.g. value-dependent trees. */ + || instantiation_dependent_expression_p (init)) return ok; if (BRACE_ENCLOSED_INITIALIZER_P (init) @@ -902,7 +906,11 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) return ok; } - init = fold_non_dependent_expr (init, complain); + init = maybe_constant_value (init); + + /* If we were asked to only check constants, return early. */ + if (const_only && !TREE_CONSTANT (init)) + return ok; if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (ftype) == REAL_TYPE) @@ -967,7 +975,7 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) { if (complain & tf_warning) warning_at (loc, OPT_Wnarrowing, "narrowing conversion of %qE " - "from %qH to %qI inside { } is ill-formed in C++11", + "from %qH to %qI is ill-formed in C++11", init, ftype, type); ok = true; } @@ -977,8 +985,7 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) { if ((!almost_ok || pedantic) && pedwarn (loc, OPT_Wnarrowing, - "narrowing conversion of %qE " - "from %qH to %qI inside { }", + "narrowing conversion of %qE from %qH to %qI", init, ftype, type) && almost_ok) inform (loc, " the expression has a constant value but is not " @@ -991,8 +998,8 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) int savederrorcount = errorcount; global_dc->pedantic_errors = 1; pedwarn (loc, OPT_Wnarrowing, - "narrowing conversion of %qE from %qH to %qI " - "inside { }", init, ftype, type); + "narrowing conversion of %qE from %qH to %qI ", + init, ftype, type); if (errorcount == savederrorcount) ok = true; global_dc->pedantic_errors = flag_pedantic_errors; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e46072fa9ab..930db3a3514 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,26 @@ +2018-08-13 Marek Polacek + + PR c++/57891 + * g++.dg/cpp0x/Wnarrowing6.C: New test. + * g++.dg/cpp0x/Wnarrowing7.C: New test. + * g++.dg/cpp0x/Wnarrowing8.C: New test. + * g++.dg/cpp0x/Wnarrowing9.C: New test. + * g++.dg/cpp0x/Wnarrowing10.C: New test. + * g++.dg/cpp0x/constexpr-47969.C: Adjust dg-error. + * g++.dg/cpp0x/constexpr-ex2.C: Likewise. + * g++.dg/cpp0x/constexpr-targ.C: Likewise. + * g++.dg/cpp0x/scoped_enum2.C: Likewise. + * g++.dg/ext/stmtexpr15.C: Likewise. + * g++.dg/gomp/pr47963.C: Likewise. + * g++.dg/init/new37.C: Likewise. + * g++.dg/init/new43.C: Likewise. + * g++.dg/other/fold1.C: Likewise. + * g++.dg/parse/array-size2.C: Likewise. + * g++.dg/template/dependent-name3.C: Likewise. + * g++.dg/cpp0x/constexpr-data2.C: Add dg-error. + * g++.dg/other/vrp1.C: Likewise. + * g++.dg/template/char1.C: Likewise. + 2018-08-13 Segher Boessenkool * gcc.target/powerpc/pr56605.c: The generated code can have an AND diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing10.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing10.C new file mode 100644 index 00000000000..8414b53e342 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing10.C @@ -0,0 +1,5 @@ +// PR c++/57891 +// { dg-do compile { target c++11 } } + +template struct S { char a[N]; }; +S<1000> s; // { dg-error "narrowing conversion" } diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing6.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing6.C new file mode 100644 index 00000000000..989d277cd00 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing6.C @@ -0,0 +1,8 @@ +// PR c++/57891 +// { dg-do compile { target c++11 } } + +template struct A {}; +A<-1> a; // { dg-error "narrowing conversion" } + +template struct B {}; +B<1000> b; // { dg-error "narrowing conversion" } diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing7.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing7.C new file mode 100644 index 00000000000..099fdfb7d81 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing7.C @@ -0,0 +1,9 @@ +// PR c++/57891 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-narrowing" } + +template struct A {}; +A<-1> a; + +template struct B {}; +B<1000> b; // { dg-warning "overflow" } diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing8.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing8.C new file mode 100644 index 00000000000..39c924c9c6c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing8.C @@ -0,0 +1,6 @@ +// PR c++/57891 +// { dg-do compile { target c++11 } } + +struct X { constexpr operator int () { return 1000; } }; +template struct C {}; +C c; // { dg-error "narrowing conversion" } diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing9.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing9.C new file mode 100644 index 00000000000..bc8a736ecb9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing9.C @@ -0,0 +1,6 @@ +// PR c++/57891 +// { dg-do compile { target c++11 } } + +// N is value-dependent, don't warn. +template struct S { char a[N]; }; // { dg-bogus "narrowing conversion" } +S<1> s; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-47969.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-47969.C index 933831b94de..201ee17b41b 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-47969.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-47969.C @@ -8,4 +8,4 @@ struct A constexpr A a = A(); -int ar[a]; // { dg-error "has non-integral type" } +int ar[a]; // { dg-error "could not convert|has non-integral type" } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C index 898102167de..dee5ed82301 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C @@ -43,4 +43,4 @@ extern template struct A3; // Use. A3 a31; -A3 a32; // { dg-warning "overflow" } +A3 a32; // { dg-error "narrowing conversion" } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C index 34b557ce76e..ceae9cb75d3 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C @@ -18,5 +18,5 @@ constexpr A a = 42; X x; // OK: unique conversion to int int ar[X::i]; // also OK -int ary[a]; // { dg-error "ambiguous|conversion|array" } ambiguous conversion +int ary[a]; // { dg-error "could not convert|ambiguous|conversion|array" } ambiguous conversion diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-targ.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-targ.C index 98bb502249a..0f1f113f92f 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-targ.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-targ.C @@ -10,4 +10,4 @@ struct B { }; constexpr A a { }; -B b; // { dg-error "template argument|converted constant" } +B b; // { dg-error "template argument|converted constant|could not convert" } diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C index bb8ad750bd0..456b0daedd1 100644 --- a/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C +++ b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C @@ -4,8 +4,8 @@ enum class E { e = 10 }; enum E2 { e2 = 10 }; struct C { - int arr[E::e]; // { dg-error "non-integral type" } + int arr[E::e]; // { dg-error "could not convert|non-integral type" } int arr2[E2::e2]; // OK - int i: E::e; // { dg-error "non-integral type" } + int i: E::e; // { dg-error "could not convert|non-integral type" } int i2: E2::e2; // OK }; diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr15.C b/gcc/testsuite/g++.dg/ext/stmtexpr15.C index 83a831cdd4c..1a60a0d3cad 100644 --- a/gcc/testsuite/g++.dg/ext/stmtexpr15.C +++ b/gcc/testsuite/g++.dg/ext/stmtexpr15.C @@ -3,5 +3,5 @@ void foo() { - int x[({ return; })]; // { dg-error "non-integral" } + int x[({ return; })]; // { dg-error "could not convert|non-integral" } } diff --git a/gcc/testsuite/g++.dg/gomp/pr47963.C b/gcc/testsuite/g++.dg/gomp/pr47963.C index 5b0c60b80a4..6be4c0e18fb 100644 --- a/gcc/testsuite/g++.dg/gomp/pr47963.C +++ b/gcc/testsuite/g++.dg/gomp/pr47963.C @@ -5,7 +5,7 @@ void foo (float n) { - int A[n][n]; // { dg-error "has non-integral type|converted constant expression" } + int A[n][n]; // { dg-error "could not convert|has non-integral type|converted constant expression" } #pragma omp parallel private(A) ; } diff --git a/gcc/testsuite/g++.dg/init/new37.C b/gcc/testsuite/g++.dg/init/new37.C index 9ecbfd7903d..2a42fda33dc 100644 --- a/gcc/testsuite/g++.dg/init/new37.C +++ b/gcc/testsuite/g++.dg/init/new37.C @@ -32,7 +32,7 @@ template void * callnew_fail_3() { - return new T[2][T::n]; // { dg-error "size of array has non-integral type|converted constant expression" } + return new T[2][T::n]; // { dg-error "could not convert|size of array has non-integral type|converted constant expression" } } struct T1 { diff --git a/gcc/testsuite/g++.dg/init/new43.C b/gcc/testsuite/g++.dg/init/new43.C index 9b0866720fe..aa40b429469 100644 --- a/gcc/testsuite/g++.dg/init/new43.C +++ b/gcc/testsuite/g++.dg/init/new43.C @@ -31,35 +31,35 @@ void test_literal () // Verify integer literal. p = new char [-1]; // { dg-error "size of array is negative" } - p = new char [2][-3]; // { dg-error "size of array is negative" } + p = new char [2][-3]; // { dg-error "size of array|narrowing conversion" } p = new char [-4][5]; // { dg-error "size of array is negative" } - p = new char [-6][-7]; // { dg-error "size of array is negative" } + p = new char [-6][-7]; // { dg-error "size of array|narrowing conversion" } p = new (p) char [-1]; // { dg-error "size of array is negative" } - p = new (p) char [2][-3]; // { dg-error "size of array is negative" } + p = new (p) char [2][-3]; // { dg-error "size of array|narrowing conversion" } p = new (p) char [-4][5]; // { dg-error "size of array is negative" } - p = new (p) char [-6][-7]; // { dg-error "size of array is negative" } + p = new (p) char [-6][-7]; // { dg-error "size of array|narrowing conversion" } p = new (p) A [-1]; // { dg-error "size of array is negative" } - p = new (p) A [2][-3]; // { dg-error "size of array is negative" } + p = new (p) A [2][-3]; // { dg-error "size of array|narrowing conversion" } p = new (p) A [-4][5]; // { dg-error "size of array is negative" } - p = new (p) A [-6][-7]; // { dg-error "size of array is negative" } + p = new (p) A [-6][-7]; // { dg-error "size of array|narrowing conversion" } p = new (p) B [-1]; // { dg-error "size of array is negative" } - p = new (p) B [2][-3]; // { dg-error "size of array is negative" } + p = new (p) B [2][-3]; // { dg-error "size of array|narrowing conversion" } p = new (p) B [-4][5]; // { dg-error "size of array is negative" } - p = new (p) B [-6][-7]; // { dg-error "size of array is negative" } + p = new (p) B [-6][-7]; // { dg-error "size of array|narrowing conversion" } p = new (&b) B [-1]; // { dg-error "size of array is negative" } - p = new (&b) B [2][-3]; // { dg-error "size of array is negative" } + p = new (&b) B [2][-3]; // { dg-error "size of array|narrowing conversion" } p = new (&b) B [-4][5]; // { dg-error "size of array is negative" } - p = new (&b) B [-6][-7]; // { dg-error "size of array is negative" } + p = new (&b) B [-6][-7]; // { dg-error "size of array|narrowing conversion" } p = new char [1 - 2]; // { dg-error "size of array is negative" } p = new (p) char [2 - 3]; // { dg-error "size of array is negative" } p = new A [2 < 1 ? -1 : -2]; // { dg-error "size of array is negative" } p = new (p) B [2 - 3 * 2]; // { dg-error "size of array is negative" } - p = new (&b) B [1][2 - 3 * 2];// { dg-error "size of array is negative" } + p = new (&b) B [1][2 - 3 * 2];// { dg-error "size of array|narrowing conversion" } } void test_constant_expression () @@ -79,35 +79,35 @@ void test_constant_expression () // Verify constant expression. p = new char [i1]; // { dg-error "size of array is negative" } - p = new char [2][i3]; // { dg-error "size of array is negative" } + p = new char [2][i3]; // { dg-error "size of array|narrowing conversion" } p = new char [i4][5]; // { dg-error "size of array is negative" } - p = new char [i6][i7]; // { dg-error "size of array is negative" } + p = new char [i6][i7]; // { dg-error "size of array|narrowing conversion" } p = new (p) char [i1]; // { dg-error "size of array is negative" } - p = new (p) char [2][i3]; // { dg-error "size of array is negative" } + p = new (p) char [2][i3]; // { dg-error "size of array|narrowing conversion" } p = new (p) char [i4][5]; // { dg-error "size of array is negative" } - p = new (p) char [i6][i7]; // { dg-error "size of array is negative" } + p = new (p) char [i6][i7]; // { dg-error "size of array|narrowing conversion" } p = new (p) A [i1]; // { dg-error "size of array is negative" } - p = new (p) A [2][i3]; // { dg-error "size of array is negative" } + p = new (p) A [2][i3]; // { dg-error "size of array|narrowing conversion" } p = new (p) A [i4][5]; // { dg-error "size of array is negative" } - p = new (p) A [i6][i7]; // { dg-error "size of array is negative" } + p = new (p) A [i6][i7]; // { dg-error "size of array|narrowing conversion" } p = new (p) B [i1]; // { dg-error "size of array is negative" } - p = new (p) B [2][i3]; // { dg-error "size of array is negative" } + p = new (p) B [2][i3]; // { dg-error "size of array|narrowing conversion" } p = new (p) B [i4][5]; // { dg-error "size of array is negative" } - p = new (p) B [i6][i7]; // { dg-error "size of array is negative" } + p = new (p) B [i6][i7]; // { dg-error "size of array|narrowing conversion" } p = new (&b) B [i1]; // { dg-error "size of array is negative" } - p = new (&b) B [2][i3]; // { dg-error "size of array is negative" } + p = new (&b) B [2][i3]; // { dg-error "size of array|narrowing conversion" } p = new (&b) B [i4][5]; // { dg-error "size of array is negative" } - p = new (&b) B [i6][i7]; // { dg-error "size of array is negative" } + p = new (&b) B [i6][i7]; // { dg-error "size of array|narrowing conversion" } p = new short [i1 - 2]; // { dg-error "size of array is negative" } p = new (p) bool [i2 - 3]; // { dg-error "size of array is negative" } p = new A [2 < 1 ? i1 : i2]; // { dg-error "size of array is negative" } p = new (p) B [2 + i3 * 2]; // { dg-error "size of array is negative" } - p = new (&b) B [1][i1 - 3 * 2];// { dg-error "size of array is negative" } + p = new (&b) B [1][i1 - 3 * 2];// { dg-error "size of array|narrowing conversion" } } void test_constexpr () @@ -132,33 +132,33 @@ void test_constexpr () // Verify constant expression. p = new char [s1]; // { dg-error "size of array is negative" } - p = new char [2][s3]; // { dg-error "size of array is negative" } + p = new char [2][s3]; // { dg-error "size of array|narrowing conversion" } p = new char [s4][5]; // { dg-error "size of array is negative" } - p = new char [s6][s7]; // { dg-error "size of array is negative" } + p = new char [s6][s7]; // { dg-error "size of array|narrowing conversion" } p = new (p) char [s1]; // { dg-error "size of array is negative" } - p = new (p) char [2][s3]; // { dg-error "size of array is negative" } + p = new (p) char [2][s3]; // { dg-error "size of array|narrowing conversion" } p = new (p) char [s4][5]; // { dg-error "size of array is negative" } - p = new (p) char [s6][s7]; // { dg-error "size of array is negative" } + p = new (p) char [s6][s7]; // { dg-error "size of array|narrowing conversion" } p = new (p) A [s1]; // { dg-error "size of array is negative" } - p = new (p) A [2][s3]; // { dg-error "size of array is negative" } + p = new (p) A [2][s3]; // { dg-error "size of array|narrowing conversion" } p = new (p) A [s4][5]; // { dg-error "size of array is negative" } - p = new (p) A [s6][s7]; // { dg-error "size of array is negative" } + p = new (p) A [s6][s7]; // { dg-error "size of array|narrowing conversion" } p = new (p) B [s1]; // { dg-error "size of array is negative" } - p = new (p) B [2][s3]; // { dg-error "size of array is negative" } + p = new (p) B [2][s3]; // { dg-error "size of array|narrowing conversion" } p = new (p) B [s4][5]; // { dg-error "size of array is negative" } - p = new (p) B [s6][s7]; // { dg-error "size of array is negative" } + p = new (p) B [s6][s7]; // { dg-error "size of array|narrowing conversion" } p = new (&b) B [s1]; // { dg-error "size of array is negative" } - p = new (&b) B [2][s3]; // { dg-error "size of array is negative" } + p = new (&b) B [2][s3]; // { dg-error "size of array|narrowing conversion" } p = new (&b) B [s4][5]; // { dg-error "size of array is negative" } - p = new (&b) B [s6][s7]; // { dg-error "size of array is negative" } + p = new (&b) B [s6][s7]; // { dg-error "size of array|narrowing conversion" } p = new int [s1 + s2]; // { dg-error "size of array is negative" } p = new (p) long [2 * s3]; // { dg-error "size of array is negative" } p = new A [s2 < s1 ? s1 : s2]; // { dg-error "size of array is negative" } p = new (p) B [s7 - s2 * 2]; // { dg-error "size of array is negative" } - p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "size of array is negative" } + p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "size of array|narrowing conversion" } } diff --git a/gcc/testsuite/g++.dg/other/fold1.C b/gcc/testsuite/g++.dg/other/fold1.C index 23d34546e0b..bf074038b04 100644 --- a/gcc/testsuite/g++.dg/other/fold1.C +++ b/gcc/testsuite/g++.dg/other/fold1.C @@ -4,5 +4,5 @@ struct A { static const int i = i; // { dg-error "not declared" } - int x[i]; // { dg-error "constant-expression" } + int x[i]; // { dg-error "constant-expression|narrowing conversion" } }; diff --git a/gcc/testsuite/g++.dg/other/vrp1.C b/gcc/testsuite/g++.dg/other/vrp1.C index 0a798c9954e..466a15b4cbb 100644 --- a/gcc/testsuite/g++.dg/other/vrp1.C +++ b/gcc/testsuite/g++.dg/other/vrp1.C @@ -9,4 +9,4 @@ long long mod (long long l, long long r) return 0LL; return l % r; } -template long long mod<-0x8000000000000000LL> (long long, long long); +template long long mod<-0x8000000000000000LL> (long long, long long); // { dg-error "template-id" "" { target { c++11 } } } diff --git a/gcc/testsuite/g++.dg/parse/array-size2.C b/gcc/testsuite/g++.dg/parse/array-size2.C index d0bc47fe746..997b95eed1a 100644 --- a/gcc/testsuite/g++.dg/parse/array-size2.C +++ b/gcc/testsuite/g++.dg/parse/array-size2.C @@ -14,7 +14,7 @@ extern void bar (char *, char *); void foo (void) { - char g[(char *) &((struct S *) 0)->b - (char *) 0]; // { dg-error "constant" } + char g[(char *) &((struct S *) 0)->b - (char *) 0]; // { dg-error "constant|narrowing conversion" } char h[(__SIZE_TYPE__) &((struct S *) 8)->b]; // { dg-error "constant" } bar (g, h); } diff --git a/gcc/testsuite/g++.dg/template/char1.C b/gcc/testsuite/g++.dg/template/char1.C index 51e72e7ad06..a6cffaaf024 100644 --- a/gcc/testsuite/g++.dg/template/char1.C +++ b/gcc/testsuite/g++.dg/template/char1.C @@ -1,4 +1,5 @@ template class String {}; -String s; // { dg-warning "overflow" } +String s; // { dg-error "narrowing conversion" "" { target c++11 } } +// { dg-warning "overflow" "" { target c++98_only } .-1 } diff --git a/gcc/testsuite/g++.dg/template/dependent-name3.C b/gcc/testsuite/g++.dg/template/dependent-name3.C index bbe6fb66266..f9d14055a11 100644 --- a/gcc/testsuite/g++.dg/template/dependent-name3.C +++ b/gcc/testsuite/g++.dg/template/dependent-name3.C @@ -11,7 +11,7 @@ template struct A template struct B { int x[A::zero]; // { dg-error "zero" } - int y[A::minus_one]; // { dg-error "negative" } + int y[A::minus_one]; // { dg-error "size of array|narrowing conversion" } }; B<0> b; -- 2.30.2