Bug 78550 - [6/7 Regression] bit field and std::initializer_list
Summary: [6/7 Regression] bit field and std::initializer_list
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 6.3
Assignee: Nathan Sidwell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-11-27 13:46 UTC by Markus Trippelsdorf
Modified: 2016-12-09 14:08 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.3.0
Known to fail: 6.2.1, 7.0
Last reconfirmed: 2016-11-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2016-11-27 13:46:40 UTC
Gavrilov Vladimir reported the following issue in a direct email to gcc-bugs:

markus@x4 tmp % cat map_bitfield.cpp
#include <map>
struct A {
  int i : 1;
};
std::map<int, A> ma{{1, {0}}};

markus@x4 tmp % g++ -c map_bitfield.cpp
map_bitfield.cpp:5:30: error: invalid initial value for member ‘i’
 std::map<int, A> ma{{1, {0}}};
                              ^

GCC-5 and other compilers accept this code.

A bit further reduced:

markus@x4 tmp % cat map_bitfield2.cpp
#include <initializer_list>
template <typename T> struct A { A(std::initializer_list<T>); };
struct B {
  int k : 1;
};
A<B> a{{0}};
markus@x4 tmp % g++ -c map_bitfield2.cpp
map_bitfield2.cpp:6:12: error: invalid initial value for member ‘k’
 A<B> a{{0}};
            ^
Comment 1 Jakub Jelinek 2016-11-28 11:06:37 UTC
Started with r230365.
Testcase without any headers:

namespace std
{
  template <class T>
  struct initializer_list
    {
      const T *a;
      __SIZE_TYPE__ b;
      constexpr initializer_list (const T *x, __SIZE_TYPE__ y) : a(x), b(y) { }
    };
}
template <typename T>
struct A {
  A (std::initializer_list<T>);
};
struct B {
  int k : 1;
};
A<B> a{{0}};
Comment 2 Nathan Sidwell 2016-12-09 12:19:08 UTC
Author: nathan
Date: Fri Dec  9 12:18:36 2016
New Revision: 243479

URL: https://gcc.gnu.org/viewcvs?rev=243479&root=gcc&view=rev
Log:
	PR c++/78550
	* convert.c (convert_to_integer_1): Maybe fold conversions to
	integral types with fewer bits than its mode.

	testsuite/
	PR c++/78550
	* g++.dg/cpp1y/pr78550.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/pr78550.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/convert.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Nathan Sidwell 2016-12-09 14:05:25 UTC
Author: nathan
Date: Fri Dec  9 14:04:53 2016
New Revision: 243484

URL: https://gcc.gnu.org/viewcvs?rev=243484&root=gcc&view=rev
Log:
	PR c++/78550
	* convert.c (convert_to_integer_1): Maybe fold conversions to
	integral types with fewer bits than its mode.

	testsuite/
	PR c++/78550
	* g++.dg/cpp1y/pr78550.C: New.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp1y/pr78550.C
Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/convert.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 4 Nathan Sidwell 2016-12-09 14:08:35 UTC
Fixed on trunk & 6 branches