From: Paolo Carlini Date: Mon, 18 Nov 2019 23:02:22 +0000 (+0000) Subject: typeck.c (cp_build_addr_expr_1): Use cp_expr_loc_or_input_loc in three places. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f5a191efecf71581a163d85da65bd53be1e58cc0;p=gcc.git typeck.c (cp_build_addr_expr_1): Use cp_expr_loc_or_input_loc in three places. /cp 2019-11-18 Paolo Carlini * typeck.c (cp_build_addr_expr_1): Use cp_expr_loc_or_input_loc in three places. (cxx_sizeof_expr): Use it in one additional place. (cxx_alignof_expr): Likewise. (lvalue_or_else): Likewise. /testsuite 2019-11-18 Paolo Carlini * g++.dg/cpp0x/addressof2.C: Test locations too. * g++.dg/cpp0x/rv-lvalue-req.C: Likewise. * g++.dg/expr/crash2.C: Likewise. * g++.dg/expr/lval1.C: Likewise. * g++.dg/expr/unary2.C: Likewise. * g++.dg/ext/lvaddr.C: Likewise. * g++.dg/ext/lvalue1.C: Likewise. * g++.dg/tree-ssa/pr20280.C: Likewise. * g++.dg/warn/Wplacement-new-size.C: Likewise. * g++.old-deja/g++.brendan/alignof.C: Likewise. * g++.old-deja/g++.brendan/sizeof2.C: Likewise. * g++.old-deja/g++.law/temps1.C: Likewise. From-SVN: r278424 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 616a04bdd1d..9bf64dfa626 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-11-18 Paolo Carlini + + * typeck.c (cp_build_addr_expr_1): Use cp_expr_loc_or_input_loc + in three places. + (cxx_sizeof_expr): Use it in one additional place. + (cxx_alignof_expr): Likewise. + (lvalue_or_else): Likewise. + 2019-11-18 Marek Polacek PR c++/91962 - ICE with reference binding and qualification conversion. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 747ae42f912..100ae8f8186 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1765,7 +1765,8 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) if (bitfield_p (e)) { if (complain & tf_error) - error ("invalid application of % to a bit-field"); + error_at (cp_expr_loc_or_input_loc (e), + "invalid application of % to a bit-field"); else return error_mark_node; e = char_type_node; @@ -1825,7 +1826,8 @@ cxx_alignof_expr (tree e, tsubst_flags_t complain) else if (bitfield_p (e)) { if (complain & tf_error) - error ("invalid application of %<__alignof%> to a bit-field"); + error_at (cp_expr_loc_or_input_loc (e), + "invalid application of %<__alignof%> to a bit-field"); else return error_mark_node; t = size_one_node; @@ -6127,7 +6129,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) if (kind == clk_none) { if (complain & tf_error) - lvalue_error (input_location, lv_addressof); + lvalue_error (cp_expr_loc_or_input_loc (arg), lv_addressof); return error_mark_node; } if (strict_lvalue && (kind & (clk_rvalueref|clk_class))) @@ -6135,7 +6137,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) if (!(complain & tf_error)) return error_mark_node; /* Make this a permerror because we used to accept it. */ - permerror (input_location, "taking address of rvalue"); + permerror (cp_expr_loc_or_input_loc (arg), + "taking address of rvalue"); } } @@ -6229,7 +6232,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) if (bitfield_p (arg)) { if (complain & tf_error) - error ("attempt to take address of bit-field"); + error_at (cp_expr_loc_or_input_loc (arg), + "attempt to take address of bit-field"); return error_mark_node; } @@ -10432,7 +10436,7 @@ lvalue_or_else (tree ref, enum lvalue_use use, tsubst_flags_t complain) if (kind == clk_none) { if (complain & tf_error) - lvalue_error (input_location, use); + lvalue_error (cp_expr_loc_or_input_loc (ref), use); return 0; } else if (kind & (clk_rvalueref|clk_class)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 199cd054767..f05382c87a7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2019-11-18 Paolo Carlini + + * g++.dg/cpp0x/addressof2.C: Test locations too. + * g++.dg/cpp0x/rv-lvalue-req.C: Likewise. + * g++.dg/expr/crash2.C: Likewise. + * g++.dg/expr/lval1.C: Likewise. + * g++.dg/expr/unary2.C: Likewise. + * g++.dg/ext/lvaddr.C: Likewise. + * g++.dg/ext/lvalue1.C: Likewise. + * g++.dg/tree-ssa/pr20280.C: Likewise. + * g++.dg/warn/Wplacement-new-size.C: Likewise. + * g++.old-deja/g++.brendan/alignof.C: Likewise. + * g++.old-deja/g++.brendan/sizeof2.C: Likewise. + * g++.old-deja/g++.law/temps1.C: Likewise. + 2019-11-18 Martin Sebor PR tree-optimization/92493 diff --git a/gcc/testsuite/g++.dg/cpp0x/addressof2.C b/gcc/testsuite/g++.dg/cpp0x/addressof2.C index 73942c5f0a5..1fa71a27b2b 100644 --- a/gcc/testsuite/g++.dg/cpp0x/addressof2.C +++ b/gcc/testsuite/g++.dg/cpp0x/addressof2.C @@ -8,19 +8,19 @@ addressof (T &x) noexcept return __builtin_addressof (x); } -auto a = __builtin_addressof (1); // { dg-error "lvalue required as unary" } -auto b = addressof (1); // { dg-error "cannot bind non-const lvalue reference of type" } +auto a = __builtin_addressof (1); // { dg-error "31:lvalue required as unary" } +auto b = addressof (1); // { dg-error "21:cannot bind non-const lvalue reference of type" } struct S { int s : 5; int t; void foo (); } s; auto c = __builtin_addressof (s); auto d = addressof (s); -auto e = __builtin_addressof (s.s); // { dg-error "attempt to take address of bit-field" } -auto f = addressof (s.s); // { dg-error "cannot bind bit-field" } -auto g = __builtin_addressof (S{}); // { dg-error "taking address of rvalue" } -auto h = addressof (S{}); // { dg-error "cannot bind non-const lvalue reference of type" } -auto i = __builtin_addressof (S::t); // { dg-error "invalid use of non-static data member" } -auto j = __builtin_addressof (S::foo); // { dg-error "invalid use of non-static member function" } +auto e = __builtin_addressof (s.s); // { dg-error "33:attempt to take address of bit-field" } +auto f = addressof (s.s); // { dg-error "23:cannot bind bit-field" } +auto g = __builtin_addressof (S{}); // { dg-error "31:taking address of rvalue" } +auto h = addressof (S{}); // { dg-error "21:cannot bind non-const lvalue reference of type" } +auto i = __builtin_addressof (S::t); // { dg-error "34:invalid use of non-static data member" } +auto j = __builtin_addressof (S::foo); // { dg-error "34:invalid use of non-static member function" } void foo (bool b) @@ -28,6 +28,6 @@ foo (bool b) lab:; char c; long long int d; - auto k = __builtin_addressof (lab); // { dg-error "was not declared in this scope" } - auto l = __builtin_addressof (b ? c : d); // { dg-error "lvalue required as unary" } + auto k = __builtin_addressof (lab); // { dg-error "33:.lab. was not declared in this scope" } + auto l = __builtin_addressof (b ? c : d); // { dg-error "35:lvalue required as unary" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-lvalue-req.C b/gcc/testsuite/g++.dg/cpp0x/rv-lvalue-req.C index b8f7ddd7895..815587d194c 100644 --- a/gcc/testsuite/g++.dg/cpp0x/rv-lvalue-req.C +++ b/gcc/testsuite/g++.dg/cpp0x/rv-lvalue-req.C @@ -4,7 +4,7 @@ template T&& declval(); int main() { - &declval(); // { dg-error "rvalue" } + &declval(); // { dg-error "16:taking address of rvalue" } declval() = declval(); // { dg-error "15:using rvalue as lvalue" } declval()++; // { dg-error "15:using rvalue as lvalue" } --declval(); // { dg-error "17:using rvalue as lvalue" } diff --git a/gcc/testsuite/g++.dg/expr/crash2.C b/gcc/testsuite/g++.dg/expr/crash2.C index 5379bb159d1..a7d60c201ca 100644 --- a/gcc/testsuite/g++.dg/expr/crash2.C +++ b/gcc/testsuite/g++.dg/expr/crash2.C @@ -8,7 +8,7 @@ int& foo::x=temp; int main() { int x = 3; - &foo::x = x; // { dg-error "" } + &foo::x = x; // { dg-error "3:lvalue required" } return 0; } diff --git a/gcc/testsuite/g++.dg/expr/lval1.C b/gcc/testsuite/g++.dg/expr/lval1.C index bed47d8e4ec..73d156c6051 100644 --- a/gcc/testsuite/g++.dg/expr/lval1.C +++ b/gcc/testsuite/g++.dg/expr/lval1.C @@ -3,5 +3,5 @@ void f () { int n; - (char) n = 1; // { dg-error "" } + (char) n = 1; // { dg-error "3:lvalue required" } } diff --git a/gcc/testsuite/g++.dg/expr/unary2.C b/gcc/testsuite/g++.dg/expr/unary2.C index 8418815918f..5962bfe19c9 100644 --- a/gcc/testsuite/g++.dg/expr/unary2.C +++ b/gcc/testsuite/g++.dg/expr/unary2.C @@ -8,8 +8,8 @@ int n; void f(void) { - -n = 0; // { dg-error "lvalue" } - +n = 0; // { dg-error "lvalue" } + -n = 0; // { dg-error "3:lvalue" } + +n = 0; // { dg-error "3:lvalue" } } template diff --git a/gcc/testsuite/g++.dg/ext/lvaddr.C b/gcc/testsuite/g++.dg/ext/lvaddr.C index 5b217d16594..6657eea5e13 100644 --- a/gcc/testsuite/g++.dg/ext/lvaddr.C +++ b/gcc/testsuite/g++.dg/ext/lvaddr.C @@ -6,5 +6,5 @@ void f() { int n; - char* p = &(char) n; // { dg-error "lvalue" } + char* p = &(char) n; // { dg-error "14:lvalue" } } diff --git a/gcc/testsuite/g++.dg/ext/lvalue1.C b/gcc/testsuite/g++.dg/ext/lvalue1.C index bf883eae21f..43f2d699b9d 100644 --- a/gcc/testsuite/g++.dg/ext/lvalue1.C +++ b/gcc/testsuite/g++.dg/ext/lvalue1.C @@ -4,7 +4,7 @@ int main () { char c; - static_cast(c) = 2; // { dg-error "lvalue" "not an lvalue" } + static_cast(c) = 2; // { dg-error "3:lvalue" "not an lvalue" } return c != 2; } diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr20280.C b/gcc/testsuite/g++.dg/tree-ssa/pr20280.C index 334ed8a75e0..61b070c10fd 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr20280.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr20280.C @@ -57,7 +57,8 @@ void f(X &x, bool b) h (b ? x.i : x.k); h (b ? x.j : x.k); - (long &)(b ? x.i : x.j); // { dg-error "address of bit-field" } - (long &)(b ? x.i : x.k); // { dg-error "address of bit-field" } - (long &)(b ? x.j : x.k); // { dg-error "address of bit-field" } + (long &)(b ? x.i : x.j); // { dg-error "18:attempt to take address of bit-field" } + (long &)(b ? x.i : x.k); // { dg-error "18:attempt to take address of bit-field" } + // { dg-error "24:attempt to take address of bit-field" "" { target *-*-* } .-1 } + (long &)(b ? x.j : x.k); // { dg-error "24:attempt to take address of bit-field" } } diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size.C index c0d753fae0e..2bafff34577 100644 --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size.C +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size.C @@ -314,11 +314,11 @@ void test (void *p, int n) new (&sssac4_2) char[sizeof sssac4_2 + 1]; // { dg-warning "placement" } // taking the address of a temporary is allowed with -fpermissive - new (&fsc ().c) int; // { dg-warning "address|placement" } - new (&fasc1 ().ac) int; // { dg-warning "address|placement" } - new (&fasc2 ().ac) int; // { dg-warning "address|placement" } - new (&fasc3 ().ac) int; // { dg-warning "address|placement" } - new (&fasc4 ().ac) int; // { dg-warning "address|placement" } + new (&fsc ().c) int; // { dg-warning "18:taking address|placement" } + new (&fasc1 ().ac) int; // { dg-warning "20:taking address|placement" } + new (&fasc2 ().ac) int; // { dg-warning "20:taking address|placement" } + new (&fasc3 ().ac) int; // { dg-warning "20:taking address|placement" } + new (&fasc4 ().ac) int; // { dg-warning "20:taking address|placement" } new (&uac1) int; // { dg-warning "placement" } new (&uac2) int; // { dg-warning "placement" } diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/alignof.C b/gcc/testsuite/g++.old-deja/g++.brendan/alignof.C index a79b6528646..a8906aff70c 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/alignof.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/alignof.C @@ -5,7 +5,7 @@ struct bar { int bit : 1; }; void foo (int *r, bar t) { // doing alignof on a bit-field should be illegal - __alignof__ (t.bit);// { dg-error "" } .* + __alignof__ (t.bit);// { dg-error "18:invalid application" } .* // both of these (a regular ref and an INDIRECT_REF) should work __alignof__ (r); diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/sizeof2.C b/gcc/testsuite/g++.old-deja/g++.brendan/sizeof2.C index 355bee74645..23176fa3583 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/sizeof2.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/sizeof2.C @@ -12,7 +12,7 @@ main() { // sizeof may not be applied to a bit-field foo f; - int i = sizeof (f.bit);// { dg-error "" } .* + int i = sizeof (f.bit);// { dg-error "21:invalid application" } .* return 0; } diff --git a/gcc/testsuite/g++.old-deja/g++.law/temps1.C b/gcc/testsuite/g++.old-deja/g++.law/temps1.C index d1ac15d6e90..618cb5f7dea 100644 --- a/gcc/testsuite/g++.old-deja/g++.law/temps1.C +++ b/gcc/testsuite/g++.old-deja/g++.law/temps1.C @@ -17,4 +17,4 @@ struct cookie }; cookie cat(&foo("apabepa"));// { dg-warning "deprecated conversion|forbids converting a string constant" "dep" } -// { dg-warning "taking address of rvalue" "add" { target *-*-* } .-1 } +// { dg-warning "13:taking address of rvalue" "add" { target *-*-* } .-1 }