From 7f3db013dc8264e39339ee4b83900ef25d0d32aa Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sat, 22 Jun 2019 14:43:00 +0000 Subject: [PATCH] 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. From-SVN: r272585 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cvt.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 93b4875de7a..31336f954c3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-06-22 Marek Polacek + + PR c++/90881 - bogus -Wunused-value in unevaluated context. + * cvt.c (convert_to_void): Don't emit unused warnings in + an unevaluated context. + 2019-06-22 Paolo Carlini * decl.c (grokdeclarator): Use id_loc, typespec_loc, and diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 1c405ecd7b6..23d2aabc483 100644 --- a/gcc/cp/cvt.c +++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 80ea5916fcc..b0b1d4ba912 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-22 Marek Polacek + + PR c++/90881 - bogus -Wunused-value in unevaluated context. + * g++.dg/cpp0x/Wunused-value1.C: New test. + 2019-06-22 Paolo Carlini * g++.dg/diagnostic/auto-storage-1.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C b/gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C new file mode 100644 index 00000000000..a0683b693a1 --- /dev/null +++ b/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 struct status : std::false_type{}; + +template struct status : 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::value, "has member"); + static_assert(!status::value, "has no member"); +} -- 2.30.2