c++: Avoid [[nodiscard]] warning in requires-expr [PR98019]
authorJason Merrill <jason@redhat.com>
Wed, 9 Dec 2020 02:47:11 +0000 (21:47 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 9 Dec 2020 05:36:07 +0000 (00:36 -0500)
If we aren't really evaluating the expression, it doesn't matter that the
return value is discarded.

gcc/cp/ChangeLog:

PR c++/98019
* cvt.c (maybe_warn_nodiscard): Check c_inhibit_evaluation_warnings.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-nodiscard1.C: Remove xfail.

gcc/cp/cvt.c
gcc/testsuite/g++.dg/cpp2a/concepts-nodiscard1.C

index bcd7c5af81c251bc16707569b93e744042d72e79..29ceaeb24ce150c8f5a957943b31b9192d4ca4d7 100644 (file)
@@ -1031,6 +1031,9 @@ cp_get_callee_fndecl_nofold (tree call)
 static void
 maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
 {
+  if (!warn_unused_result || c_inhibit_evaluation_warnings)
+    return;
+
   tree call = expr;
   if (TREE_CODE (expr) == TARGET_EXPR)
     call = TARGET_EXPR_INITIAL (expr);
index 907e68b1fc2b5947b571dc5b1a3d5209b2476a09..3d5cd85bc943e9ec6f842d36bdc1b43fe497ddd3 100644 (file)
@@ -1,6 +1,6 @@
 // PR c++/98019
 // { dg-do compile { target c++20 } }
-// { dg-excess-errors *-*-* }
+// Don't give [[nodiscard]] warning for an expression requirement.
 
 template <class T, class U> concept same_as = __is_same_as (T, U);