[Bug c++/86743] New: Compilation failure when initializing POD structs containing constant member
ldr709 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jul 30 19:51:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86743
Bug ID: 86743
Summary: Compilation failure when initializing POD structs
containing constant member
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ldr709 at gmail dot com
Target Milestone: ---
With this code:
struct A
{
int i;
const int b;
};
// The union is to verify that A is a type that can be used in a union.
union U
{
A a;
int b;
};
int main()
{
U a = {1, 1};
U b = {2, 1};
}
I get an error message:
$ g++ -std=c++03
a.cpp:9:4: error: member ‘A U::a’ with copy assignment operator not allowed in
union
A a;
^
a.cpp:9:4: note: unrestricted unions only available with -std=c++11 or
-std=gnu++11
$ g++ ---version
g++ (GCC) 8.1.1 20180531
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For reasoning about why this should compile without failure, see
https://stackoverflow.com/questions/27665567/pod-structs-containing-constant-member
More information about the Gcc-bugs
mailing list