From c3a63fb3854392af65a191154e3586e7f5a1066e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 8 Dec 2020 21:47:11 -0500 Subject: [PATCH] c++: Avoid [[nodiscard]] warning in requires-expr [PR98019] 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 | 3 +++ gcc/testsuite/g++.dg/cpp2a/concepts-nodiscard1.C | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index bcd7c5af81c..29ceaeb24ce 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -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); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-nodiscard1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-nodiscard1.C index 907e68b1fc2..3d5cd85bc94 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-nodiscard1.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-nodiscard1.C @@ -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 concept same_as = __is_same_as (T, U); -- 2.30.2