Title says it all. In an unevaluated context, the result is never used anyways. Other compilers do ignore [[nodiscard]] in those contexts already. Example code: struct A { [[nodiscard]] static int match() { return 42; } }; template<typename T> auto g() -> decltype( T::match(), bool() ) { return T::match(); } int main() { g<A>(); } Leads to: <source>: In substitution of 'template<class T> decltype ((T::match(), bool())) g() [with T = A]': <source>:14:10: required from here <source>:7:31: warning: ignoring return value of 'static int A::match()', declared with attribute nodiscard [-Wunused-result] 7 | auto g() -> decltype( T::match(), bool() ) | ~~~~~~~~^~ <source>:3:30: note: declared here 3 | [[nodiscard]] static int match() { return 42; } | ^~~~~ Compiler returned: 0 See https://godbolt.org/z/OQEnaD
The problem is specific to [[nodiscard]] and doesn't affect attribute warn_unused_result (either the traditional form or [[gnu::warn_unused_result]]).
*** Bug 92477 has been marked as a duplicate of this bug. ***
Author: mpolacek Date: Wed Nov 13 15:59:53 2019 New Revision: 278147 URL: https://gcc.gnu.org/viewcvs?rev=278147&root=gcc&view=rev Log: PR c++/89070 - bogus [[nodiscard]] warning in SFINAE. 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. * cvt.c (convert_to_void): Guard maybe_warn_nodiscard calls with tf_warning. * g++.dg/cpp1z/nodiscard7.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp1z/nodiscard7.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cvt.c trunk/gcc/testsuite/ChangeLog
Fixed.