This is an archive of the discontinued LLVM Phabricator instance.

Unnamed bitfields don't block constant evaluation of constexpr constructors
ClosedPublic

Authored by jordan_rose on Oct 17 2017, 8:03 PM.

Details

Summary

C++14 [dcl.constexpr]p4 states that in the body of a constexpr constructor,

every non-variant non-static data member and base class sub-object shall be initialized

However, [class.bit]p2 notes that

Unnamed bit-fields are not members and cannot be initialized.

Therefore, we should make sure to filter them out of the check that all fields are initialized.

Fixing this makes the constant evaluator a bit smarter, and specifically allows constexpr constructors to avoid tripping -Wglobal-constructors when the type contains unnamed bitfields.

Diff Detail

Repository
rL LLVM

Event Timeline

jordan_rose created this revision.Oct 17 2017, 8:03 PM
aaron.ballman accepted this revision.Oct 18 2017, 7:54 AM
aaron.ballman added a subscriber: aaron.ballman.

Aside from some minor nits, LGTM!

test/SemaCXX/constant-expression-cxx11.cpp
1924

Can remove the spurious newline.

test/SemaCXX/warn-global-constructors.cpp
130

Does this namespace require a name? If so, can it be named different than the struct declared within it?

148

Please ensure the file retains its newline.

This revision is now accepted and ready to land.Oct 18 2017, 7:54 AM

Thanks, Aaron!

test/SemaCXX/warn-global-constructors.cpp
130

I'm just trying to keep from having my test cases collide with the rest of the file and any future additions. I'll change it. (There's no PR or Radar for this at the moment; I just came across it while working on something else.)