If a union has explicit initializers for some members, we shouldn't delete
its default constructor.
Fixes https://github.com/llvm/llvm-project/issues/48416.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Generally looks good to me. Do we do anything special if there are multiple initializers? Also, can we have a codegen test that validates that we actually construct it correctly (and perhaps a constexpr test for the same!)?
clang/lib/Sema/SemaDeclCXX.cpp | ||
---|---|---|
9163 | This way you don't need the assert! | |
9167 | else needs curleys, since its associated 'if' has them. |
Added constexpr + codegen tests.
If we have multiple initializers it's an error that's already diagnosed, I assume the error recovery just drops any initializer after the first.
LGTM, I wlll let @royjacobson give the final approval after reviewing codegen tests.
clang/lib/Sema/SemaDeclCXX.cpp | ||
---|---|---|
9161–9162 |
Precommit CI found related failures:
/var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGen/union-non-trivial-member.cpp:29:16: error: found empty check string with prefix 'CHECK:' // CHECK-NEXT: ^ error: unknown argument: '-g0'
clang/test/CodeGen/union-non-trivial-member.cpp | ||
---|---|---|
31 | Looking more closely, this test is a little over specific. First, you can just do CHECK: to start each function, that way you don't have the blank lines. In the top function, all we care about is the call void <name>s, so the rest of the lines can go away. Since you're checking function's define line, you can count on ordering that way rather than check-next. This middle function should use more wildcard/placeholders, checking fully specific names like this or this.addr is a mistake, as those aren't guaranteed to be there. Also, all the 'align' checks are likely to make this fail in post-commit. on the last function, we don't even care about the parameters list, so you just need the call void <name> part. |
clang/test/CodeGen/union-non-trivial-member.cpp | ||
---|---|---|
31 | removed the non-essential parts. |
clang/test/CodeGen/union-non-trivial-member.cpp | ||
---|---|---|
23 | ||
24 | Don't need the entry: line, | |
25 | Wildcards are implicit at the end of a line. | |
26 | ||
27 | This and the line after it aren't really necessary/valuable, particularly in case we get debug info/builtin/etc added later. | |
30 | I typically suggest not requiring a space either before or after a {{.*}} block, since that wont match 'empty'. | |
31 | Same here, skip the entry , ret, and closing curley brace line. | |
32 | same advise as above on the following ones too. |
No worries, there is definitely somewhat of an art to writing a codegen test that won't be fragile/overspecified, I've made a few more suggestions to make it more clear/easier, else this LGTM. Feel free to put the rest of the codegen test suggestions up for further review, but if you're comfortable with them, you may commit instead.