public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] c++/89070 - bogus [[nodiscard]] warning in SFINAE.
@ 2019-11-12 17:04 Marek Polacek
  2019-11-13 15:43 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2019-11-12 17:04 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

This is a complaint that we issue a [[nodiscard]] warning even in SFINAE
contexts.  Here 'complain' is tf_decltype, but not tf_warning so I guess
we can fix it as below.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-11-12  Marek Polacek  <polacek@redhat.com>

	PR c++/89070 - bogus [[nodiscard]] warning in SFINAE.
	* cvt.c (convert_to_void): Guard maybe_warn_nodiscard calls with
	tf_warning.

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

diff --git gcc/cp/cvt.c gcc/cp/cvt.c
index d41aeb8f1fc..23facb77634 100644
--- gcc/cp/cvt.c
+++ gcc/cp/cvt.c
@@ -1201,7 +1201,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
 	if (DECL_DESTRUCTOR_P (fn))
 	  return expr;
 
-      maybe_warn_nodiscard (expr, implicit);
+      if (complain & tf_warning)
+	maybe_warn_nodiscard (expr, implicit);
       break;
 
     case INDIRECT_REF:
@@ -1357,7 +1358,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
                 && !is_reference)
               warning_at (loc, OPT_Wunused_value, "value computed is not used");
             expr = TREE_OPERAND (expr, 0);
-	    if (TREE_CODE (expr) == CALL_EXPR)
+	    if (TREE_CODE (expr) == CALL_EXPR
+		&& (complain & tf_warning))
 	      maybe_warn_nodiscard (expr, implicit);
           }
 
@@ -1435,7 +1437,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
 					   AGGR_INIT_EXPR_ARGP (init));
 	    }
 	}
-      maybe_warn_nodiscard (expr, implicit);
+      if (complain & tf_warning)
+	maybe_warn_nodiscard (expr, implicit);
       break;
 
     default:;
diff --git gcc/testsuite/g++.dg/cpp1z/nodiscard7.C gcc/testsuite/g++.dg/cpp1z/nodiscard7.C
new file mode 100644
index 00000000000..80dac63e41e
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1z/nodiscard7.C
@@ -0,0 +1,18 @@
+// PR c++/89070 - bogus [[nodiscard]] warning in SFINAE.
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+    [[nodiscard]] static int match() { return 42; }
+};
+
+template<typename T>
+auto g() -> decltype( T::match(), bool() )
+{
+    return T::match();
+}
+
+int main()
+{
+    g<A>();
+}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] c++/89070 - bogus [[nodiscard]] warning in SFINAE.
  2019-11-12 17:04 [C++ PATCH] c++/89070 - bogus [[nodiscard]] warning in SFINAE Marek Polacek
@ 2019-11-13 15:43 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-11-13 15:43 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

OK.

On Tue, Nov 12, 2019 at 11:45 AM Marek Polacek <polacek@redhat.com> wrote:

> This is a complaint that we issue a [[nodiscard]] warning even in SFINAE
> contexts.  Here 'complain' is tf_decltype, but not tf_warning so I guess
> we can fix it as below.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2019-11-12  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/89070 - bogus [[nodiscard]] warning in SFINAE.
>         * cvt.c (convert_to_void): Guard maybe_warn_nodiscard calls with
>         tf_warning.
>
>         * g++.dg/cpp1z/nodiscard7.C: New test.
>
> diff --git gcc/cp/cvt.c gcc/cp/cvt.c
> index d41aeb8f1fc..23facb77634 100644
> --- gcc/cp/cvt.c
> +++ gcc/cp/cvt.c
> @@ -1201,7 +1201,8 @@ convert_to_void (tree expr, impl_conv_void implicit,
> tsubst_flags_t complain)
>         if (DECL_DESTRUCTOR_P (fn))
>           return expr;
>
> -      maybe_warn_nodiscard (expr, implicit);
> +      if (complain & tf_warning)
> +       maybe_warn_nodiscard (expr, implicit);
>        break;
>
>      case INDIRECT_REF:
> @@ -1357,7 +1358,8 @@ convert_to_void (tree expr, impl_conv_void implicit,
> tsubst_flags_t complain)
>                  && !is_reference)
>                warning_at (loc, OPT_Wunused_value, "value computed is not
> used");
>              expr = TREE_OPERAND (expr, 0);
> -           if (TREE_CODE (expr) == CALL_EXPR)
> +           if (TREE_CODE (expr) == CALL_EXPR
> +               && (complain & tf_warning))
>               maybe_warn_nodiscard (expr, implicit);
>            }
>
> @@ -1435,7 +1437,8 @@ convert_to_void (tree expr, impl_conv_void implicit,
> tsubst_flags_t complain)
>                                            AGGR_INIT_EXPR_ARGP (init));
>             }
>         }
> -      maybe_warn_nodiscard (expr, implicit);
> +      if (complain & tf_warning)
> +       maybe_warn_nodiscard (expr, implicit);
>        break;
>
>      default:;
> diff --git gcc/testsuite/g++.dg/cpp1z/nodiscard7.C
> gcc/testsuite/g++.dg/cpp1z/nodiscard7.C
> new file mode 100644
> index 00000000000..80dac63e41e
> --- /dev/null
> +++ gcc/testsuite/g++.dg/cpp1z/nodiscard7.C
> @@ -0,0 +1,18 @@
> +// PR c++/89070 - bogus [[nodiscard]] warning in SFINAE.
> +// { dg-do compile { target c++11 } }
> +
> +struct A
> +{
> +    [[nodiscard]] static int match() { return 42; }
> +};
> +
> +template<typename T>
> +auto g() -> decltype( T::match(), bool() )
> +{
> +    return T::match();
> +}
> +
> +int main()
> +{
> +    g<A>();
> +}
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-13 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 17:04 [C++ PATCH] c++/89070 - bogus [[nodiscard]] warning in SFINAE Marek Polacek
2019-11-13 15:43 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).