From: Paolo Carlini Date: Wed, 2 Oct 2019 23:23:51 +0000 (+0000) Subject: init.c (build_new): Use cp_expr_loc_or_input_loc in two places. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f5fc32e4a38cee21d1935fd04ad19726f76c06a9;p=gcc.git init.c (build_new): Use cp_expr_loc_or_input_loc in two places. /cp 2019-10-03 Paolo Carlini * init.c (build_new): Use cp_expr_loc_or_input_loc in two places. * name-lookup.c (do_pushdecl): Use DECL_SOURCE_LOCATION. (push_class_level_binding_1): Likewise. (set_decl_namespace): Likewise. /testsuite 2019-10-03 Paolo Carlini * g++.dg/diagnostic/integral-array-size-1.C: New. * g++.dg/cpp0x/alias-decl-1.C: Test location(s) too. * g++.dg/init/new43.C: Likewise. * g++.dg/lookup/friend12.C: Likewise. * g++.dg/lookup/pr79766.C: Likewise. * g++.dg/lookup/pr84375.C: Likewise. * g++.dg/other/new-size-type.C: Likewise. From-SVN: r276496 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 72790626500..bd3592a4725 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-10-03 Paolo Carlini + + * init.c (build_new): Use cp_expr_loc_or_input_loc in two places. + * name-lookup.c (do_pushdecl): Use DECL_SOURCE_LOCATION. + (push_class_level_binding_1): Likewise. + (set_decl_namespace): Likewise. + 2019-10-03 Jakub Jelinek * constexpr.c (cxx_eval_constant_expression) : If diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 76fa030e927..857f360c761 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3754,7 +3754,8 @@ build_new (vec **placement, tree type, tree nelts, if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false)) { if (complain & tf_error) - permerror (input_location, "size in array new must have integral type"); + permerror (cp_expr_loc_or_input_loc (nelts), + "size in array new must have integral type"); else return error_mark_node; } @@ -3769,7 +3770,8 @@ build_new (vec **placement, tree type, tree nelts, less than zero. ... If the expression is a constant expression, the program is ill-fomed. */ if (TREE_CODE (cst_nelts) == INTEGER_CST - && !valid_array_size_p (input_location, cst_nelts, NULL_TREE, + && !valid_array_size_p (cp_expr_loc_or_input_loc (nelts), + cst_nelts, NULL_TREE, complain & tf_error)) return error_mark_node; diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 4d01a54055e..ff6d5ee6984 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3080,8 +3080,9 @@ do_pushdecl (tree decl, bool is_friend) /* In a local class, a friend function declaration must find a matching decl in the innermost non-class scope. [class.friend/11] */ - error ("friend declaration %qD in local class without " - "prior local declaration", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "friend declaration %qD in local class without " + "prior local declaration", decl); /* Don't attempt to push it. */ return error_mark_node; } @@ -4451,9 +4452,9 @@ push_class_level_binding_1 (tree name, tree x) tree scope = context_for_name_lookup (x); if (TYPE_P (scope) && same_type_p (scope, current_class_type)) { - error ("%qD has the same name as the class in which it is " - "declared", - x); + error_at (DECL_SOURCE_LOCATION (x), + "%qD has the same name as the class in which it is " + "declared", x); return false; } } @@ -4757,7 +4758,8 @@ set_decl_namespace (tree decl, tree scope, bool friendp) /* Writing "N::i" to declare something directly in "N" is invalid. */ if (CP_DECL_CONTEXT (decl) == current_namespace && at_namespace_scope_p ()) - error ("explicit qualification in declaration of %qD", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "explicit qualification in declaration of %qD", decl); return; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b9fcbb08332..27659f4bb4e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2019-10-03 Paolo Carlini + + * g++.dg/diagnostic/integral-array-size-1.C: New. + * g++.dg/cpp0x/alias-decl-1.C: Test location(s) too. + * g++.dg/init/new43.C: Likewise. + * g++.dg/lookup/friend12.C: Likewise. + * g++.dg/lookup/pr79766.C: Likewise. + * g++.dg/lookup/pr84375.C: Likewise. + * g++.dg/other/new-size-type.C: Likewise. + 2019-10-03 Jakub Jelinek * g++.dg/ext/constexpr-attr-cleanup1.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-1.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-1.C index 43284d76978..24b05209223 100644 --- a/gcc/testsuite/g++.dg/cpp0x/alias-decl-1.C +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-1.C @@ -12,5 +12,5 @@ template struct Ptr {}; // { dg-error "specialization" } struct A { using A = int; // { dg-error "11:ISO C\\+\\+ forbids nested type .A." } -// { dg-error "same name as" "" { target c++11 } .-1 } +// { dg-error "11:.using A = int. has the same name as" "" { target c++11 } .-1 } }; diff --git a/gcc/testsuite/g++.dg/diagnostic/integral-array-size-1.C b/gcc/testsuite/g++.dg/diagnostic/integral-array-size-1.C new file mode 100644 index 00000000000..31d67c58d61 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/integral-array-size-1.C @@ -0,0 +1,7 @@ +template +void foo(T a) +{ + new int[a]; // { dg-error "11:size in array new must have integral type" } +} + +template void foo(float); diff --git a/gcc/testsuite/g++.dg/init/new43.C b/gcc/testsuite/g++.dg/init/new43.C index e2ad67d8307..880e330907f 100644 --- a/gcc/testsuite/g++.dg/init/new43.C +++ b/gcc/testsuite/g++.dg/init/new43.C @@ -30,36 +30,36 @@ void test_literal () B b; // Verify integer literal. - p = new char [-1]; // { dg-error "size .-1. of array is negative" } - p = new char [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new char [-4][5]; // { dg-error "size .-4. of array is negative" } - p = new char [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) char [-1]; // { dg-error "size .-1. of array is negative" } - p = new (p) char [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) char [-4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) char [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) A [-1]; // { dg-error "size .-1. of array is negative" } - p = new (p) A [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) A [-4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) A [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) B [-1]; // { dg-error "size .-1. of array is negative" } - p = new (p) B [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) B [-4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) B [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (&b) B [-1]; // { dg-error "size .-1. of array is negative" } - p = new (&b) B [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (&b) B [-4][5]; // { dg-error "size .-4. of array is negative" } - p = new (&b) B [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new char [1 - 2]; // { dg-error "size .-1. of array is negative" } - p = new (p) char [2 - 3]; // { dg-error "size .-1. of array is negative" } - p = new A [2 < 1 ? -1 : -2]; // { dg-error "size .-2. of array is negative" } - p = new (p) B [2 - 3 * 2]; // { dg-error "size .-4. of array is negative" } - p = new (&b) B [1][2 - 3 * 2];// { dg-error "size .-4. of array|narrowing conversion" } + p = new char [-1]; // { dg-error "19:size .-1. of array is negative" } + p = new char [2][-3]; // { dg-error "22:size .-3. of array|narrowing conversion" } + p = new char [-4][5]; // { dg-error "19:size .-4. of array is negative" } + p = new char [-6][-7]; // { dg-error "19:size .-6. of array|narrowing conversion" } + // { dg-error "23:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) char [-1]; // { dg-error "23:size .-1. of array is negative" } + p = new (p) char [2][-3]; // { dg-error "26:size .-3. of array|narrowing conversion" } + p = new (p) char [-4][5]; // { dg-error "23:size .-4. of array is negative" } + p = new (p) char [-6][-7]; // { dg-error "23:size .-6. of array|narrowing conversion" } + // { dg-error "27:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) A [-1]; // { dg-error "20:size .-1. of array is negative" } + p = new (p) A [2][-3]; // { dg-error "23:size .-3. of array|narrowing conversion" } + p = new (p) A [-4][5]; // { dg-error "20:size .-4. of array is negative" } + p = new (p) A [-6][-7]; // { dg-error "20:size .-6. of array|narrowing conversion" } + // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) B [-1]; // { dg-error "20:size .-1. of array is negative" } + p = new (p) B [2][-3]; // { dg-error "23:size .-3. of array|narrowing conversion" } + p = new (p) B [-4][5]; // { dg-error "20:size .-4. of array is negative" } + p = new (p) B [-6][-7]; // { dg-error "size .-6. of array|narrowing conversion" } + // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 } + p = new (&b) B [-1]; // { dg-error "21:size .-1. of array is negative" } + p = new (&b) B [2][-3]; // { dg-error "24:size .-3. of array|narrowing conversion" } + p = new (&b) B [-4][5]; // { dg-error "21:size .-4. of array is negative" } + p = new (&b) B [-6][-7]; // { dg-error "21:size .-6. of array|narrowing conversion" } + // { dg-error "25:size .-7. of array" "" { target *-*-* } .-1 } + p = new char [1 - 2]; // { dg-error "21:size .-1. of array is negative" } + p = new (p) char [2 - 3]; // { dg-error "25:size .-1. of array is negative" } + p = new A [2 < 1 ? -1 : -2]; // { dg-error "22:size .-2. of array is negative" } + p = new (p) B [2 - 3 * 2]; // { dg-error "22:size .-4. of array is negative" } + p = new (&b) B [1][2 - 3 * 2];// { dg-error "26:size .-4. of array|narrowing conversion" } } void test_constant_expression () @@ -78,36 +78,36 @@ void test_constant_expression () static const int i7 = -7; // Verify constant expression. - p = new char [i1]; // { dg-error "size .-1. of array is negative" } - p = new char [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new char [i4][5]; // { dg-error "size .-4. of array is negative" } - p = new char [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) char [i1]; // { dg-error "size .-1. of array is negative" } - p = new (p) char [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) char [i4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) char [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) A [i1]; // { dg-error "size .-1. of array is negative" } - p = new (p) A [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) A [i4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) A [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) B [i1]; // { dg-error "size .-1. of array is negative" } - p = new (p) B [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) B [i4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) B [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (&b) B [i1]; // { dg-error "size .-1. of array is negative" } - p = new (&b) B [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (&b) B [i4][5]; // { dg-error "size .-4. of array is negative" } - p = new (&b) B [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new short [i1 - 2]; // { dg-error "size .-3. of array is negative" } - p = new (p) bool [i2 - 3]; // { dg-error "size .-5. of array is negative" } - p = new A [2 < 1 ? i1 : i2]; // { dg-error "size .-2. of array is negative" } - p = new (p) B [2 + i3 * 2]; // { dg-error "size .-4. of array is negative" } - p = new (&b) B [1][i1 - 3 * 2];// { dg-error "size .-7. of array|narrowing conversion" } + p = new char [i1]; // { dg-error "19:size .-1. of array is negative" } + p = new char [2][i3]; // { dg-error "22:size .-3. of array|narrowing conversion" } + p = new char [i4][5]; // { dg-error "19:size .-4. of array is negative" } + p = new char [i6][i7]; // { dg-error "19:size .-6. of array|narrowing conversion" } + // { dg-error "23:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) char [i1]; // { dg-error "23:size .-1. of array is negative" } + p = new (p) char [2][i3]; // { dg-error "26:size .-3. of array|narrowing conversion" } + p = new (p) char [i4][5]; // { dg-error "23:size .-4. of array is negative" } + p = new (p) char [i6][i7]; // { dg-error "23:size .-6. of array|narrowing conversion" } + // { dg-error "27:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) A [i1]; // { dg-error "20:size .-1. of array is negative" } + p = new (p) A [2][i3]; // { dg-error "23:size .-3. of array|narrowing conversion" } + p = new (p) A [i4][5]; // { dg-error "20:size .-4. of array is negative" } + p = new (p) A [i6][i7]; // { dg-error "20:size .-6. of array|narrowing conversion" } + // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) B [i1]; // { dg-error "20:size .-1. of array is negative" } + p = new (p) B [2][i3]; // { dg-error "23:size .-3. of array|narrowing conversion" } + p = new (p) B [i4][5]; // { dg-error "20:size .-4. of array is negative" } + p = new (p) B [i6][i7]; // { dg-error "20:size .-6. of array|narrowing conversion" } + // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 } + p = new (&b) B [i1]; // { dg-error "21:size .-1. of array is negative" } + p = new (&b) B [2][i3]; // { dg-error "24:size .-3. of array|narrowing conversion" } + p = new (&b) B [i4][5]; // { dg-error "21:size .-4. of array is negative" } + p = new (&b) B [i6][i7]; // { dg-error "21:size .-6. of array|narrowing conversion" } + // { dg-error "25:size .-7. of array" "" { target *-*-* } .-1 } + p = new short [i1 - 2]; // { dg-error "23:size .-3. of array is negative" } + p = new (p) bool [i2 - 3]; // { dg-error "26:size .-5. of array is negative" } + p = new A [2 < 1 ? i1 : i2]; // { dg-error "22:size .-2. of array is negative" } + p = new (p) B [2 + i3 * 2]; // { dg-error "22:size .-4. of array is negative" } + p = new (&b) B [1][i1 - 3 * 2];// { dg-error "27:size .-7. of array|narrowing conversion" } } void test_constexpr () @@ -131,36 +131,36 @@ void test_constexpr () #endif // Verify constant expression. - p = new char [s1]; // { dg-error "size .-1. of array is negative" } - p = new char [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new char [s4][5]; // { dg-error "size .-4. of array is negative" } - p = new char [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) char [s1]; // { dg-error "size .-1. of array is negative" } - p = new (p) char [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) char [s4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) char [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) A [s1]; // { dg-error "size .-1. of array is negative" } - p = new (p) A [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) A [s4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) A [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (p) B [s1]; // { dg-error "size .-1. of array is negative" } - p = new (p) B [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (p) B [s4][5]; // { dg-error "size .-4. of array is negative" } - p = new (p) B [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new (&b) B [s1]; // { dg-error "size .-1. of array is negative" } - p = new (&b) B [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } - p = new (&b) B [s4][5]; // { dg-error "size .-4. of array is negative" } - p = new (&b) B [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } - - p = new int [s1 + s2]; // { dg-error "size .-3. of array is negative" } - p = new (p) long [2 * s3]; // { dg-error "size .-6. of array is negative" } + p = new char [s1]; // { dg-error "19:size .-1. of array is negative" } + p = new char [2][s3]; // { dg-error "22:size .-3. of array|narrowing conversion" } + p = new char [s4][5]; // { dg-error "19:size .-4. of array is negative" } + p = new char [s6][s7]; // { dg-error "19:size .-6. of array|narrowing conversion" } + // { dg-error "23:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) char [s1]; // { dg-error "23:size .-1. of array is negative" } + p = new (p) char [2][s3]; // { dg-error "26:size .-3. of array|narrowing conversion" } + p = new (p) char [s4][5]; // { dg-error "23:size .-4. of array is negative" } + p = new (p) char [s6][s7]; // { dg-error "23:size .-6. of array|narrowing conversion" } + // { dg-error "27:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) A [s1]; // { dg-error "20:size .-1. of array is negative" } + p = new (p) A [2][s3]; // { dg-error "23:size .-3. of array|narrowing conversion" } + p = new (p) A [s4][5]; // { dg-error "20:size .-4. of array is negative" } + p = new (p) A [s6][s7]; // { dg-error "20:size .-6. of array|narrowing conversion" } + // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 } + p = new (p) B [s1]; // { dg-error "20:size .-1. of array is negative" } + p = new (p) B [2][s3]; // { dg-error "23:size .-3. of array|narrowing conversion" } + p = new (p) B [s4][5]; // { dg-error "20:size .-4. of array is negative" } + p = new (p) B [s6][s7]; // { dg-error "20:size .-6. of array|narrowing conversion" } + // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 } + p = new (&b) B [s1]; // { dg-error "21:size .-1. of array is negative" } + p = new (&b) B [2][s3]; // { dg-error "24:size .-3. of array|narrowing conversion" } + p = new (&b) B [s4][5]; // { dg-error "21:size .-4. of array is negative" } + p = new (&b) B [s6][s7]; // { dg-error "21:size .-6. of array|narrowing conversion" } + // { dg-error "25:size .-7. of array" "" { target *-*-* } .-1 } + p = new int [s1 + s2]; // { dg-error "21:size .-3. of array is negative" } + p = new (p) long [2 * s3]; // { dg-error "25:size .-6. of array is negative" } p = new A [s2 < s1 ? s1 : s2]; // { dg-error "size .-1. of array is negative" } - p = new (p) B [s7 - s2 * 2]; // { dg-error "size .-3. of array is negative" } - p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "size .-2. of array|narrowing conversion" } + p = new (p) B [s7 - s2 * 2]; // { dg-error "23:size .-3. of array is negative" } + p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "27:size .-2. of array|narrowing conversion" } } /* Prune out pedantic warnins (turned into errors via -pedantic-errors). diff --git a/gcc/testsuite/g++.dg/lookup/friend12.C b/gcc/testsuite/g++.dg/lookup/friend12.C index eb61fb52378..612b0da0299 100644 --- a/gcc/testsuite/g++.dg/lookup/friend12.C +++ b/gcc/testsuite/g++.dg/lookup/friend12.C @@ -5,6 +5,6 @@ void foo() extern void bar (int); // not the bar we are looking for struct A { - friend void bar(); // { dg-error "without prior local declaration" } + friend void bar(); // { dg-error "17:friend declaration .void bar\\(\\). in local class without prior local declaration" } }; } diff --git a/gcc/testsuite/g++.dg/lookup/pr79766.C b/gcc/testsuite/g++.dg/lookup/pr79766.C index de9bbb5fab9..09f09fa67d4 100644 --- a/gcc/testsuite/g++.dg/lookup/pr79766.C +++ b/gcc/testsuite/g++.dg/lookup/pr79766.C @@ -24,6 +24,6 @@ void ::R () // OK -> Z::R void S (); -void ::S () // { dg-error "explicit qualification" } +void ::S () // { dg-error "6:explicit qualification" } { } diff --git a/gcc/testsuite/g++.dg/lookup/pr84375.C b/gcc/testsuite/g++.dg/lookup/pr84375.C index 24cdcb2c407..1b086e15694 100644 --- a/gcc/testsuite/g++.dg/lookup/pr84375.C +++ b/gcc/testsuite/g++.dg/lookup/pr84375.C @@ -4,6 +4,6 @@ void foo() { struct A { - friend void A(); // { dg-error "local class without prior local" } + friend void A(); // { dg-error "17:friend declaration .void A\\(\\). in local class without prior local" } }; } diff --git a/gcc/testsuite/g++.dg/other/new-size-type.C b/gcc/testsuite/g++.dg/other/new-size-type.C index a99d747026a..3411641e041 100644 --- a/gcc/testsuite/g++.dg/other/new-size-type.C +++ b/gcc/testsuite/g++.dg/other/new-size-type.C @@ -5,5 +5,5 @@ const char* foo() { - return new char[~static_cast(0)];// { dg-error "exceeds maximum object size" } + return new char[~static_cast(0)];// { dg-error "21:exceeds maximum object size" } }