forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++: designated init and aggregate members [PR103337]
Our C++20 designated initializer handling was broken with members of class type; we would find the relevant member and then try to find a member of the member with the same name. Or we would sometimes ignore the designator entirely. The former problem is fixed by the change to reshape_init_class, the latter by the change to reshape_init_r. PR c++/103337 PR c++/102740 PR c++/103299 PR c++/102538 gcc/cp/ChangeLog: * decl.c (reshape_init_class): Avoid looking for designator after we found it. (reshape_init_r): Keep looking for designator. gcc/testsuite/ChangeLog: * g++.dg/ext/flexary3.C: Remove one error. * g++.dg/parse/pr43765.C: Likewise. * g++.dg/cpp2a/desig22.C: New test. * g++.dg/cpp2a/desig23.C: New test. * g++.dg/cpp2a/desig24.C: New test. * g++.dg/cpp2a/desig25.C: New test.
- Loading branch information
Showing
7 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// PR c++/103337 | ||
// { dg-do compile { target c++20 } } | ||
|
||
struct op_t { | ||
struct put_t { | ||
int x; | ||
} put; | ||
}; | ||
|
||
op_t x{0}; // OK | ||
op_t y{.put=0}; // bogus error: 'op_t::put_t' has no non-static data member named 'put' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// PR c++/102740 | ||
// { dg-do compile { target c++20 } } | ||
// { dg-additional-options -Wmissing-braces } | ||
|
||
typedef struct { | ||
union { | ||
struct { | ||
const void* content; | ||
} put; | ||
}; | ||
} op_t; | ||
|
||
op_t f(const char* alias) { | ||
return op_t{ | ||
.put = | ||
{ | ||
.content = alias, | ||
}, | ||
}; // { dg-warning "missing braces" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// PR c++/103299 | ||
// { dg-do compile { target c++20 } } | ||
|
||
struct foo { | ||
union { | ||
int fp1{}; | ||
char fp2; | ||
}; | ||
}; | ||
|
||
static_assert(foo{.fp2={}}.fp2 == 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// PR c++/102538 | ||
// { dg-do run { target c++20 } } | ||
|
||
struct X { union { char r8[8]; int r32[2]; }; }; | ||
struct Y { X v[1]; }; | ||
Y x = { { { .r32 = { 5, 6 } } } }; | ||
|
||
int | ||
main () | ||
{ | ||
if (x.v[0].r32[0] != 5 || x.v[0].r32[1] != 6) | ||
__builtin_abort (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters