]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/92732 (Bit-field of scoped enumeration type cannot be initialized)
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Dec 2019 17:34:14 +0000 (18:34 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Dec 2019 17:34:14 +0000 (18:34 +0100)
Backported from mainline
2019-12-03  Jakub Jelinek  <jakub@redhat.com>

PR c++/92732
* typeck2.c (digest_nsdmi_init): For bitfields, use
DECL_BIT_FIELD_TYPE instead of TREE_TYPE.

* g++.dg/cpp2a/bitfield3.C: Don't expect narrowing conversion
warnings.
* g++.dg/cpp2a/bitfield4.C: New test.

From-SVN: r279665

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/bitfield3.C
gcc/testsuite/g++.dg/cpp2a/bitfield4.C [new file with mode: 0644]

index b727db680e7e5a0f2d710f79affbf1a104e431b7..7b09a30d0ab2c8946af08fe3ee2ab847a1deaa5d 100644 (file)
@@ -3,6 +3,10 @@
        Backported from mainline
        2019-12-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/92732
+       * typeck2.c (digest_nsdmi_init): For bitfields, use
+       DECL_BIT_FIELD_TYPE instead of TREE_TYPE.
+
        PR c++/92695
        * constexpr.c (cxx_bind_parameters_in_call): For virtual calls,
        adjust the first argument to point to the derived object rather
index bdb98f844350e825c26b3cc4e2ca6e44d340e80a..b406368a5d6ed0b0c9a9271376482adfdd76fb9d 100644 (file)
@@ -1291,6 +1291,8 @@ digest_nsdmi_init (tree decl, tree init, tsubst_flags_t complain)
   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
 
   tree type = TREE_TYPE (decl);
+  if (DECL_BIT_FIELD_TYPE (decl))
+    type = DECL_BIT_FIELD_TYPE (decl);
   int flags = LOOKUP_IMPLICIT;
   if (DIRECT_LIST_INIT_P (init))
     {
index b8f1c54098db4046538033bc5b9f0c2f723de4a3..a116f43b453879bafd008eeb938067b1e2e3c19b 100644 (file)
@@ -3,6 +3,11 @@
        Backported from mainline
        2019-12-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/92732
+       * g++.dg/cpp2a/bitfield3.C: Don't expect narrowing conversion
+       warnings.
+       * g++.dg/cpp2a/bitfield4.C: New test.
+
        PR c++/92695
        * g++.dg/cpp2a/constexpr-virtual14.C: New test.
 
index 511c8894703fc4f4b7925b18dde280a47520c7b8..5482da490e2b65f44f475bad2e74ed232312e4f3 100644 (file)
@@ -15,11 +15,9 @@ const int b = 0;
 struct S {
   int c : 5 = 2 * a;                   // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int d : 6 { c + a };                 // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-                                       // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int e : true ? 7 : a = 3;
   int f : (true ? 8 : b) = d + a;      // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int g : (true ? 9 : b) { f + a };    // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-                                       // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int h : 1 || new int { 0 };
   int i = g + a;
 };
@@ -28,11 +26,9 @@ template <bool V, int W>
 struct U {
   int j : W = 3 * a;                   // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int k : W { j + a };                 // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-                                       // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int l : V ? 7 : a = 3;
   int m : (V ? W : b) = k + a;         // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int n : (V ? W : b) { m + a };       // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-                                       // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int o : 1 || new int { 0 };
   int p = n + a;
 };
diff --git a/gcc/testsuite/g++.dg/cpp2a/bitfield4.C b/gcc/testsuite/g++.dg/cpp2a/bitfield4.C
new file mode 100644 (file)
index 0000000..bbfa86c
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/92732
+// { dg-do compile { target c++17 } }
+// { dg-options "" }
+
+enum class byte : unsigned char { };
+using uint8_t = unsigned char;
+
+struct T
+{
+  byte a : 2 = byte{0};        // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
+  uint8_t b : 2 = 0;   // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
+} t;