This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Should std::byte copy-list-initialization fail?
- From: Jeffrey Walton <noloader at gmail dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 17 Jul 2017 04:15:25 -0400
- Subject: Re: Should std::byte copy-list-initialization fail?
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8k6WquriwvvWBp1DuOeqeRO=gRrGb_rSY_124LZuZDTAA@mail.gmail.com> <CAH6eHdTwd5Da_0MFR-b06H+E5p-5=eVEgwDDO25Myb+C-j-uMw@mail.gmail.com>
- Reply-to: noloader at gmail dot com
On Thu, Jul 13, 2017 at 3:55 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 13 July 2017 at 18:58, Jeffrey Walton wrote:
>> I'm working on Fedora 26 with GCC 7.1.1. I'm testing some C++17 code
>> and learning where some of the pain points are.
>>
>> $ cat test.cxx
>> #include <cstddef>
>> int main(int argc, char* argv[])
>> {
>> std::byte b1 {0x65};
>> std::byte b2 = {0x66};
>> return 0;
>> }
>>
>> test.cxx: In function ‘int main(int, char**)’:
>> test.cxx:5:23: error: cannot convert ‘int’ to ‘std::byte’ in initialization
>> std::byte b2 = {0x66};
>> ^
>>
>> It seems like there should be enough information for the compiler to
>> determine the list argument type and avoid the error (for b2) like in
>> the first example (for b1).
>>
>> Is the copy-list-initialization failure expected?
>
> Yes. You can't initialize a scoped enumeration type with an implicit conversion.
>
> enum class E { };
> E e = { 0 }; // error
> E e{ 0 }; // ok in C++17, error in C++14
Thanks Jonathan.
The comments explain my confusion. It seemed like both should succeed,
or both should fail. It looks like special accommodations were made
for list-initialization under C++17.
Jeff