From: Jonathan Wakely Date: Sat, 6 Aug 2016 00:07:05 +0000 (+0100) Subject: Harmonize diagnostics for invalid reference binding X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa76f2c63032aaa2214c015d7d5f33257bd3ed66;p=gcc.git Harmonize diagnostics for invalid reference binding gcc/cp: * call.c (convert_like_real): Harmonize diagnostics for invalid reference binding. gcc/testsuite: * call.c (convert_like_real): Harmonize diagnostics for invalid reference binding. * g++.dg/conversion/pr16333.C: Adjust dg-error regexp. * g++.dg/conversion/pr41426.C: Likewise. * g++.dg/conversion/pr66211.C: Likewise. * g++.dg/cpp1y/lambda-init9.C: Likewise. * g++.dg/init/ref8.C: Likewise. * g++.old-deja/g++.law/cvt20.C: Likewise. * g++.old-deja/g++.mike/p9732c.C: Likewise. From-SVN: r239184 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b2307e928f3..4efbc7b153f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-08-06 Jonathan Wakely + + * call.c (convert_like_real): Harmonize diagnostics for invalid + reference binding. + 2016-08-05 Martin Sebor * constexpr.c (cxx_eval_store_expression): Remove hyphen from diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 802c3258e8f..918661ab786 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6710,15 +6710,15 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, tree extype = TREE_TYPE (expr); if (TYPE_REF_IS_RVALUE (ref_type) && lvalue_p (expr)) - error_at (loc, "cannot bind %qT lvalue to %qT", - extype, totype); + error_at (loc, "cannot bind rvalue reference of type %qT to " + "lvalue of type %qT", totype, extype); else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr) && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type))) - error_at (loc, "invalid initialization of non-const reference of " - "type %qT from an rvalue of type %qT", totype, extype); + error_at (loc, "cannot bind non-const lvalue reference of " + "type %qT to an rvalue of type %qT", totype, extype); else if (!reference_compatible_p (TREE_TYPE (totype), extype)) - error_at (loc, "binding %qT to reference of type %qT " - "discards qualifiers", extype, totype); + error_at (loc, "binding reference of type %qT to %qT " + "discards qualifiers", totype, extype); else gcc_unreachable (); maybe_print_user_conv_context (convs); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e9792962c62..06d6bae6b5a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2016-08-06 Jonathan Wakely + + * g++.dg/conversion/pr16333.C: Adjust dg-error regexp. + * g++.dg/conversion/pr41426.C: Likewise. + * g++.dg/conversion/pr66211.C: Likewise. + * g++.dg/cpp1y/lambda-init9.C: Likewise. + * g++.dg/init/ref8.C: Likewise. + * g++.old-deja/g++.law/cvt20.C: Likewise. + * g++.old-deja/g++.mike/p9732c.C: Likewise. + 2016-08-05 Patrick Palka PR tree-optimization/18046 diff --git a/gcc/testsuite/g++.dg/conversion/pr16333.C b/gcc/testsuite/g++.dg/conversion/pr16333.C index 810c12a9acb..a00bc5c167c 100644 --- a/gcc/testsuite/g++.dg/conversion/pr16333.C +++ b/gcc/testsuite/g++.dg/conversion/pr16333.C @@ -7,4 +7,4 @@ struct X { int a[3]; X foo1 () { return a; } const X &foo2 () { return a; } // { dg-warning "returning reference to temporary" } -X &foo3 () { return a; } // { dg-error "invalid initialization" } +X &foo3 () { return a; } // { dg-error "cannot bind non-const lvalue ref" } diff --git a/gcc/testsuite/g++.dg/conversion/pr41426.C b/gcc/testsuite/g++.dg/conversion/pr41426.C index 78ec5fbdfbf..5493a91ecfa 100644 --- a/gcc/testsuite/g++.dg/conversion/pr41426.C +++ b/gcc/testsuite/g++.dg/conversion/pr41426.C @@ -23,7 +23,7 @@ const A &g3() A &g4() { float f[] = {1.1f, 2.3f}; - return f; // { dg-error "invalid initialization" } + return f; // { dg-error "cannot bind non-const lvalue ref" } } struct B diff --git a/gcc/testsuite/g++.dg/conversion/pr66211.C b/gcc/testsuite/g++.dg/conversion/pr66211.C index 49d2478888a..770e8a0e20f 100644 --- a/gcc/testsuite/g++.dg/conversion/pr66211.C +++ b/gcc/testsuite/g++.dg/conversion/pr66211.C @@ -7,5 +7,5 @@ int main() { int x = 0; double y = 1; - f(1 > 0 ? x : y); // { dg-error "from an rvalue" } + f(1 > 0 ? x : y); // { dg-error "cannot bind .* to an rvalue" } } diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init9.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init9.C index a86f03e0f1d..795d036ca75 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-init9.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init9.C @@ -2,5 +2,5 @@ void f() { - [&x=1]{}; // { dg-error "cannot capture|invalid initialization" } + [&x=1]{}; // { dg-error "cannot capture|cannot bind non-const lvalue ref" } } diff --git a/gcc/testsuite/g++.dg/init/ref8.C b/gcc/testsuite/g++.dg/init/ref8.C index 406cc10401d..5b68a2f0033 100644 --- a/gcc/testsuite/g++.dg/init/ref8.C +++ b/gcc/testsuite/g++.dg/init/ref8.C @@ -6,5 +6,5 @@ A operator*(A, A); A& operator+=(A& a, const A& b) { - return a = a * b; // { dg-error "non-const reference" } + return a = a * b; // { dg-error "non-const lvalue reference" } } diff --git a/gcc/testsuite/g++.old-deja/g++.law/cvt20.C b/gcc/testsuite/g++.old-deja/g++.law/cvt20.C index f5c703bccfd..97b465fe06f 100644 --- a/gcc/testsuite/g++.old-deja/g++.law/cvt20.C +++ b/gcc/testsuite/g++.old-deja/g++.law/cvt20.C @@ -16,5 +16,5 @@ void f(const char *& x) // { dg-message "argument" } int main() { - f ("foo"); // { dg-error "invalid initialization" } + f ("foo"); // { dg-error "cannot bind non-const lvalue reference" } } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p9732c.C b/gcc/testsuite/g++.old-deja/g++.mike/p9732c.C index 9239a0978ec..247d372de7d 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p9732c.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p9732c.C @@ -2,4 +2,4 @@ // prms-id: 9732 struct foo {}; -foo& x() { return foo(); } // { dg-error "invalid init" } +foo& x() { return foo(); } // { dg-error "cannot bind non-const lvalue" }