Hi!

When passing expressions with decltype(nullptr) type with side-effects to
ellipsis, we pass (void *)0 instead, but for the side-effects evaluate them
on the lhs of a COMPOUND_EXPR.  Unfortunately that means we warn about it
if the expression is a call to nodiscard marked function, even when the
result is really used, just needs to be transformed.

Fixed by adding a warning_sentinel, bootstrapped/regtested on x86_64-linux
and i686-linux, ok for trunk?

2021-05-25  Jakub Jelinek  <ja...@redhat.com>

        PR c++/100666
        * call.c (convert_arg_to_ellipsis): For expressions with NULLPTR_TYPE
        and side-effects, temporarily disable -Wunused-result warning when
        building COMPOUND_EXPR.

        * g++.dg/cpp1z/nodiscard8.C: New test.

--- gcc/cp/call.c.jj    2021-05-21 10:34:09.139562923 +0200
+++ gcc/cp/call.c       2021-05-24 18:36:35.041184496 +0200
@@ -8178,7 +8178,10 @@ convert_arg_to_ellipsis (tree arg, tsubs
     {
       arg = mark_rvalue_use (arg);
       if (TREE_SIDE_EFFECTS (arg))
-       arg = cp_build_compound_expr (arg, null_pointer_node, complain);
+       {
+         warning_sentinel w(warn_unused_result);
+         arg = cp_build_compound_expr (arg, null_pointer_node, complain);
+       }
       else
        arg = null_pointer_node;
     }
--- gcc/testsuite/g++.dg/cpp1z/nodiscard8.C.jj  2021-05-24 19:14:43.472158432 
+0200
+++ gcc/testsuite/g++.dg/cpp1z/nodiscard8.C     2021-05-24 19:13:54.959688504 
+0200
@@ -0,0 +1,11 @@
+// PR c++/100666
+// { dg-do compile { target c++11 } }
+
+[[nodiscard]] decltype(nullptr) bar ();
+extern void foo (...);
+
+void
+baz ()
+{
+  foo (bar ());        // { dg-bogus "ignoring return value of '\[^\n\r]*', 
declared with attribute 'nodiscard'" }
+}

        Jakub

Reply via email to