]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix missing SFINAE when binding a bit-field to a reference (PR 93729)
authorPatrick Palka <ppalka@redhat.com>
Tue, 3 Mar 2020 17:27:33 +0000 (12:27 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sun, 8 Mar 2020 14:45:46 +0000 (10:45 -0400)
We are unconditionally emitting an error here, without first checking complain.

gcc/cp/ChangeLog:

PR c++/93729
* call.c (convert_like_real): Check complain before emitting an error
about binding a bit-field to a reference.

gcc/testsuite/ChangeLog:

PR c++/93729
* g++.dg/concepts/pr93729.C: New test.

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/concepts/pr93729.C [new file with mode: 0644]

index 48ef75c732e3d3e49137f8b8dd0aa74bc90ce785..f32c27e8ee7d2efdd9e2358fe7ba04b93b9808be 100644 (file)
@@ -1,5 +1,9 @@
 2020-03-08  Patrick Palka  <ppalka@redhat.com>
 
+       PR c++/93729
+       * call.c (convert_like_real): Check complain before emitting an error
+       about binding a bit-field to a reference.
+
        * cxx-pretty-print.c (cxx_pretty_printer::simple_type_specifier)
        [TYPENAME_TYPE]: Print the TYPENAME_TYPE_FULLNAME instead of the
        TYPE_NAME.
index 85bbd043a1df3429396a21fd89ce52cf7fffc4ef..c0340d96f3c817360b5c66182f355ce81405405f 100644 (file)
@@ -7730,15 +7730,18 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
              {
                /* If the reference is volatile or non-const, we
                   cannot create a temporary.  */
-               if (lvalue & clk_bitfield)
-                 error_at (loc, "cannot bind bit-field %qE to %qT",
-                           expr, ref_type);
-               else if (lvalue & clk_packed)
-                 error_at (loc, "cannot bind packed field %qE to %qT",
-                           expr, ref_type);
-               else
-                 error_at (loc, "cannot bind rvalue %qE to %qT",
-                           expr, ref_type);
+               if (complain & tf_error)
+                 {
+                   if (lvalue & clk_bitfield)
+                     error_at (loc, "cannot bind bit-field %qE to %qT",
+                               expr, ref_type);
+                   else if (lvalue & clk_packed)
+                     error_at (loc, "cannot bind packed field %qE to %qT",
+                               expr, ref_type);
+                   else
+                     error_at (loc, "cannot bind rvalue %qE to %qT",
+                               expr, ref_type);
+                 }
                return error_mark_node;
              }
            /* If the source is a packed field, and we must use a copy
index 99e2e4260109bca201e71a5630528e5ac27d74e5..a1a371b948f858f37668b81f7581ca48efc04e3e 100644 (file)
@@ -1,5 +1,8 @@
 2020-03-08  Patrick Palka  <ppalka@redhat.com>
 
+       PR c++/93729
+       * g++.dg/concepts/pr93729.C: New test.
+
        * g++.dg/concepts/diagnostic4.C: New test.
 
 2020-03-08  H.J. Lu  <hongjiu.lu@intel.com>
diff --git a/gcc/testsuite/g++.dg/concepts/pr93729.C b/gcc/testsuite/g++.dg/concepts/pr93729.C
new file mode 100644 (file)
index 0000000..7397edb
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++2a } }
+
+// PR c++/93729
+
+struct B
+{
+  int a:4;
+  int b:4;
+};
+
+template<typename T>
+concept c1
+  = requires(T x, void(f)(int &)) { f(x.a); }; // { dg-bogus "cannot bind" }
+
+static_assert(!c1<B>);