PR c++/90881 - bogus -Wunused-value in unevaluated context.
authorMarek Polacek <polacek@redhat.com>
Sat, 22 Jun 2019 14:43:00 +0000 (14:43 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sat, 22 Jun 2019 14:43:00 +0000 (14:43 +0000)
* 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
gcc/cp/cvt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wunused-value1.C [new file with mode: 0644]

index 93b4875de7a4dc397ad352773a86e195704c3b26..31336f954c34e5c1be24006d56eb68453de127f5 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-22  Marek Polacek  <polacek@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.
+
 2019-06-22  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * decl.c (grokdeclarator): Use id_loc, typespec_loc, and
index 1c405ecd7b620dd564422a6ba4733a3671570c68..23d2aabc4836d09cdf506296a1a640f45de6087c 100644 (file)
@@ -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.  */
index 80ea5916fcc77b754179731f6257cf5158ac7fc3..b0b1d4ba912201f7a791769255cda7101cec4a51 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/90881 - bogus -Wunused-value in unevaluated context.
+       * g++.dg/cpp0x/Wunused-value1.C: New test.
+
 2019-06-22  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * 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 (file)
index 0000000..a0683b6
--- /dev/null
@@ -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");
+}