Commit 6fcb7ebb by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/92732 (Bit-field of scoped enumeration type cannot be initialized)

	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: r278923
parent e0daa2c8
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.
2019-12-03 Jason Merrill <jason@redhat.com> 2019-12-03 Jason Merrill <jason@redhat.com>
Jakub Jelinek <jakub@redhat.com> Jakub Jelinek <jakub@redhat.com>
......
...@@ -1335,6 +1335,8 @@ digest_nsdmi_init (tree decl, tree init, tsubst_flags_t complain) ...@@ -1335,6 +1335,8 @@ digest_nsdmi_init (tree decl, tree init, tsubst_flags_t complain)
gcc_assert (TREE_CODE (decl) == FIELD_DECL); gcc_assert (TREE_CODE (decl) == FIELD_DECL);
tree type = TREE_TYPE (decl); tree type = TREE_TYPE (decl);
if (DECL_BIT_FIELD_TYPE (decl))
type = DECL_BIT_FIELD_TYPE (decl);
int flags = LOOKUP_IMPLICIT; int flags = LOOKUP_IMPLICIT;
if (DIRECT_LIST_INIT_P (init)) if (DIRECT_LIST_INIT_P (init))
{ {
......
2019-12-03 Jakub Jelinek <jakub@redhat.com> 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++/92705 PR c++/92705
* g++.dg/conversion/ambig4.C: New test. * g++.dg/conversion/ambig4.C: New test.
......
...@@ -15,11 +15,9 @@ const int b = 0; ...@@ -15,11 +15,9 @@ const int b = 0;
struct S { struct S {
int c : 5 = 2 * a; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } 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 } } 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 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 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 } } 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 h : 1 || new int { 0 };
int i = g + a; int i = g + a;
}; };
...@@ -28,11 +26,9 @@ template <bool V, int W> ...@@ -28,11 +26,9 @@ template <bool V, int W>
struct U { struct U {
int j : W = 3 * a; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } 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 } } 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 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 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 } } 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 o : 1 || new int { 0 };
int p = n + a; int p = n + a;
}; };
......
// 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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment