As Jon points out in the PR, emitting -Wunused warnings in unevaluated contexts doesn't make a whole lot of sense, because in such contexts, we're not reading the values in any case. Disabling this particular warning is trivial. There are likely other warnings like this, but I haven't audited them.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-06-13 Marek Polacek <pola...@redhat.com> PR c++/90881 - bogus -Wunused-value in unevaluated context. * cvt.c (convert_to_void): Don't emit unused warnings in an unevaluated context. * g++.dg/cpp0x/Wunused-value1.C: New test. diff --git gcc/cp/cvt.c gcc/cp/cvt.c index 1c405ecd7b6..23d2aabc483 100644 --- gcc/cp/cvt.c +++ gcc/cp/cvt.c @@ -1518,7 +1518,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) if (implicit != ICV_CAST && warn_unused_value && !TREE_NO_WARNING (expr) - && !processing_template_decl) + && !processing_template_decl + && !cp_unevaluated_operand) { /* The middle end does not warn about expressions that have been explicitly cast to void, so we must do so here. */ diff --git gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C new file mode 100644 index 00000000000..a0683b693a1 --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C @@ -0,0 +1,20 @@ +// PR c++/90881 +// { dg-do compile { target c++11 } } +// { dg-options "-Wall" } + +namespace std { + struct true_type { static const bool value = true; }; + struct false_type { static const bool value = false; }; +} + +template <typename T, typename = void> struct status : std::false_type{}; + +template <typename T> struct status<T, decltype(T::member, void())> : std::true_type {}; // { dg-bogus "left operand of comma operator has no effect" } + +struct s1{int member;}; +struct s2{int _member;}; + +int main(){ + static_assert(status<s1>::value, "has member"); + static_assert(!status<s2>::value, "has no member"); +}