https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118355
Bug ID: 118355
Summary: New error in GCC 12
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: thomgree at cisco dot com
Target Milestone: ---
Minimal example code:
int main()
{
enum MY_ENUM
{
ZERO,
};
struct FOO
{
MY_ENUM type = ZERO;
};
struct ARR
{
FOO array[1] = {};
};
ARR arr;
arr = {};
return 0;
}
Error message:
<source>: In function 'int main()':
<source>:19:10: error: no match for 'operator=' (operand types are
'main()::ARR' and '<brace-enclosed initializer list>')
19 | arr = {};
| ^
<source>:13:10: note: candidate: 'constexpr main()::ARR&
main()::ARR::operator=(const main()::ARR&)'
13 | struct ARR
| ^~~
<source>:13:10: note: no known conversion for argument 1 from
'<brace-enclosed initializer list>' to 'const main()::ARR&'
<source>:13:10: note: candidate: 'constexpr main()::ARR&
main()::ARR::operator=(main()::ARR&&)'
<source>:13:10: note: no known conversion for argument 1 from
'<brace-enclosed initializer list>' to 'main()::ARR&&'
Compiler returned: 1
This code compiles in GCC 11 and in Clang, but not in GCC 12.
https://godbolt.org/z/PcoPhG8qM
The use of enum, and the C array, and all of the member initialisations all
seem to be required to trigger it.