From: Jason Merrill Date: Wed, 9 Dec 2020 02:47:11 +0000 (-0500) Subject: c++: Avoid [[nodiscard]] warning in requires-expr [PR98019] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c3a63fb3854392af65a191154e3586e7f5a1066e;p=gcc.git 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. --- 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);