From: Jakub Jelinek Date: Mon, 25 Jun 2018 17:30:03 +0000 (+0200) Subject: backport: re PR c++/84076 (Warning about objects through POD mistakenly claims the... X-Git-Tag: releases/gcc-6.5.0~211 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26fc9ec3b3bf4d1c63dbc1b27d7c24515f794868;p=thirdparty%2Fgcc.git backport: re PR c++/84076 (Warning about objects through POD mistakenly claims the object is a pointer) Backported from mainline 2018-03-09 Jason Merrill Jakub Jelinek PR c++/84076 * call.c (convert_arg_to_ellipsis): Instead of cp_build_addr_expr build ADDR_EXPR with REFERENCE_TYPE. (build_over_call): For purposes of check_function_arguments, if argarray[j] is ADDR_EXPR with REFERENCE_TYPE created above, use its operand rather than the argument itself. * g++.dg/warn/Wformat-2.C: New test. From-SVN: r262073 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2748e4df8476..4b783360ade1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,16 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-09 Jason Merrill + Jakub Jelinek + + PR c++/84076 + * call.c (convert_arg_to_ellipsis): Instead of cp_build_addr_expr + build ADDR_EXPR with REFERENCE_TYPE. + (build_over_call): For purposes of check_function_arguments, if + argarray[j] is ADDR_EXPR with REFERENCE_TYPE created above, use + its operand rather than the argument itself. + 2018-03-02 Jakub Jelinek PR c++/84662 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 3bdd5fef3f31..f148b39083b9 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6837,7 +6837,7 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) "passing objects of non-trivially-copyable " "type %q#T through %<...%> is conditionally supported", arg_type); - return cp_build_addr_expr (arg, complain); + return build1 (ADDR_EXPR, build_reference_type (arg_type), arg); } } @@ -7578,7 +7578,15 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) tree *fargs = (!nargs ? argarray : (tree *) alloca (nargs * sizeof (tree))); for (j = 0; j < nargs; j++) - fargs[j] = maybe_constant_value (argarray[j]); + { + /* For -Wformat undo the implicit passing by hidden reference + done by convert_arg_to_ellipsis. */ + if (TREE_CODE (argarray[j]) == ADDR_EXPR + && TREE_CODE (TREE_TYPE (argarray[j])) == REFERENCE_TYPE) + fargs[j] = TREE_OPERAND (argarray[j], 0); + else + fargs[j] = maybe_constant_value (argarray[j]); + } check_function_arguments (input_location, TREE_TYPE (fn), nargs, fargs); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c42c350d879..033d1458dfcb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,12 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-09 Jason Merrill + Jakub Jelinek + + PR c++/84076 + * g++.dg/warn/Wformat-2.C: New test. + 2018-03-09 Jakub Jelinek PR c++/84767 diff --git a/gcc/testsuite/g++.dg/warn/Wformat-2.C b/gcc/testsuite/g++.dg/warn/Wformat-2.C new file mode 100644 index 000000000000..ff8b54b48998 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wformat-2.C @@ -0,0 +1,17 @@ +// PR c++/84076 +// { dg-do compile } +// { dg-options "-Wformat" } + +struct S { ~S (); }; +struct T { T (); T (const T &); }; + +void +foo () +{ + S s; + T t; + __builtin_printf ("%s\n", s); // { dg-warning "format '%s' expects argument of type 'char\\*', but argument 2 has type 'S'" } + __builtin_printf ("%s\n", t); // { dg-warning "format '%s' expects argument of type 'char\\*', but argument 2 has type 'T'" } + __builtin_printf ("%s\n", &s);// { dg-warning "format '%s' expects argument of type 'char\\*', but argument 2 has type 'S\\*'" } + __builtin_printf ("%s\n", &t);// { dg-warning "format '%s' expects argument of type 'char\\*', but argument 2 has type 'T\\*'" } +}