This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix diagnostic printing of COMPONENT_REF with ARROW_EXPR first operand (PR c++/79304)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 31 Jan 2017 16:15:30 -0500
- Subject: Re: [C++ PATCH] Fix diagnostic printing of COMPONENT_REF with ARROW_EXPR first operand (PR c++/79304)
- Authentication-results: sourceware.org; auth=none
- References: <20170131182923.GJ14051@tucnak>
OK.
On Tue, Jan 31, 2017 at 1:29 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> For dependent expression followed by -> and identifier or ~ identifier,
> the parser creates COMPONENT_REF with ARROW_EXPR as its first argument.
> When printing that, we actually print expr->.identifier , which is not
> what the user typed. The following patch omits the undesirable dot in
> that case, we know that dump_expr on the ARROW_EXPR already printed ->
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2017-01-31 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/79304
> * error.c (dump_expr) <case COMPONENT_REF>: Don't print .
> after ARROW_EXPR.
>
> * g++.dg/diagnostic/pr79304.C: New test.
>
> --- gcc/cp/error.c.jj 2017-01-21 02:26:06.000000000 +0100
> +++ gcc/cp/error.c 2017-01-31 17:03:17.737123973 +0100
> @@ -2247,7 +2247,8 @@ dump_expr (cxx_pretty_printer *pp, tree
> else
> {
> dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
> - pp_cxx_dot (pp);
> + if (TREE_CODE (ob) != ARROW_EXPR)
> + pp_cxx_dot (pp);
> }
> dump_expr (pp, TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
> }
> --- gcc/testsuite/g++.dg/diagnostic/pr79304.C.jj 2017-01-31 17:08:17.347318113 +0100
> +++ gcc/testsuite/g++.dg/diagnostic/pr79304.C 2017-01-31 17:08:01.000000000 +0100
> @@ -0,0 +1,20 @@
> +// PR c++/79304
> +// { dg-do compile }
> +
> +struct C { };
> +
> +template<class T>
> +struct X
> +{
> + C* c;
> +
> + void f() {
> + this->c.s(); // { dg-error "->c" }
> + }
> +};
> +
> +int main()
> +{
> + X<int> x;
> + x.f();
> +}
>
> Jakub