[C++ PATCH] Don't ignore side-effects on decltype(nullptr) typed args passed to ... (PR c++/92992)
Jason Merrill
jason@redhat.com
Fri Dec 20 23:07:00 GMT 2019
On 12/18/19 6:40 PM, Jakub Jelinek wrote:
> Hi!
>
> While looking at PR92666, I've spotted a wrong-code issue where we ignore
> any side-effects on arguments passed to ellipsis if they have
> decltype(nullptr) type.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk and release branches?
>
> 2019-12-19 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/92992
> * call.c (convert_arg_to_ellipsis): For decltype(nullptr) arguments
> that have side-effects use cp_build_compound_expr.
OK.
> * g++.dg/cpp0x/nullptr45.C: New test.
>
> --- gcc/cp/call.c.jj 2019-12-17 10:19:51.013282361 +0100
> +++ gcc/cp/call.c 2019-12-18 18:23:01.441357443 +0100
> @@ -7822,7 +7822,12 @@ convert_arg_to_ellipsis (tree arg, tsubs
> arg = convert_to_real_nofold (double_type_node, arg);
> }
> else if (NULLPTR_TYPE_P (arg_type))
> - arg = null_pointer_node;
> + {
> + if (TREE_SIDE_EFFECTS (arg))
> + arg = cp_build_compound_expr (arg, null_pointer_node, complain);
> + else
> + arg = null_pointer_node;
> + }
> else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
> {
> if (SCOPED_ENUM_P (arg_type))
> --- gcc/testsuite/g++.dg/cpp0x/nullptr45.C.jj 2019-12-18 18:37:48.537933751 +0100
> +++ gcc/testsuite/g++.dg/cpp0x/nullptr45.C 2019-12-18 18:37:17.290406672 +0100
> @@ -0,0 +1,24 @@
> +// PR c++/92992
> +// { dg-do run { target c++11 } }
> +
> +int a;
> +
> +void
> +bar (int, ...)
> +{
> +}
> +
> +decltype (nullptr)
> +baz ()
> +{
> + a++;
> + return nullptr;
> +}
> +
> +int
> +main ()
> +{
> + bar (0, baz ());
> + if (a != 1)
> + __builtin_abort ();
> +}
>
> Jakub
>
More information about the Gcc-patches
mailing list