This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Add __is_aggregate type-trait
ClosedPublic

Authored by EricWF on Mar 30 2017, 3:21 PM.

Details

Summary

LWG 2911 adds std::is_aggregate to the library, which requires a new builtin trait. This patch implements __is_aggregate.

Diff Detail

Event Timeline

EricWF created this revision.Mar 30 2017, 3:21 PM
EricWF updated this revision to Diff 93555.Mar 30 2017, 3:25 PM
  • Move test to correct file.
EricWF updated this revision to Diff 93709.Mar 31 2017, 2:35 PM
  • Update the doc to reflect that GCC has implemented this trait (and to assume MS will as well).
  • Rewrite the tests using static_assert over god-awful old style array asserts.
EricWF updated this revision to Diff 93715.Mar 31 2017, 3:19 PM
  • Correctly report array types as aggregates. (Woops!)
  • Also report vector types as aggregates. This behavior mirrors GCC.
  • report _Complex int and _Complex float as aggregates as well. Currently GCC does not have this behavior, but since they support aggregate initialization I think it makes sense to support them as aggregates.
aaron.ballman added inline comments.Apr 3 2017, 5:05 PM
docs/LanguageExtensions.rst
996

Has Microsoft already implemented this? If not, do we want to wait for them before claiming they implement it as well?

lib/Sema/SemaExprCXX.cpp
4234

Is there benefit to diverging from GCC's behavior here for _Complex types?

EricWF added a subscriber: STL_MSFT.Apr 3 2017, 5:20 PM
EricWF added inline comments.
docs/LanguageExtensions.rst
996

I asked @STL_MSFT to ping the frontend team to confirm they were planning on implementing it with this name. I was concerned this doc would never get updated otherwise.

lib/Sema/SemaExprCXX.cpp
4234

_Complex types act as if they are an array of 2 elements, and hence support aggregate initialization.

Ironically the GCC maintainer who implemented is_aggregate pointed this case out to me. I've pinged him to ask why he chose not to support it, or if the change is in the works.

aaron.ballman added inline comments.Apr 3 2017, 5:36 PM
docs/LanguageExtensions.rst
996

Seems reasonable. My concern is that we claim Microsoft implements this when they don't (yet) and someone uses this documentation to try to force Microsoft's hand. However, it seems that this documentation not being updated is the far more likely scenario. ;-)

lib/Sema/SemaExprCXX.cpp
4089

If I understand properly, this change is required by LWG 2015 for existing type traits *and* is needed for is_aggregate()? If so, it probably should be a separate patch doing just LWG 2015 (and tests) and a second one for is_aggregate().

4234

Thanks! I think supporting it makes sense.

STL_MSFT added inline comments.Apr 3 2017, 5:46 PM
docs/LanguageExtensions.rst
996

MS intends to implement this hook under this name. No ETA yet.

EricWF added inline comments.Apr 3 2017, 5:48 PM
lib/Sema/SemaExprCXX.cpp
4089

Ack.

aaron.ballman added inline comments.Apr 3 2017, 5:56 PM
docs/LanguageExtensions.rst
996

Lovely, then I'm happy with the documentation as-is.

EricWF updated this revision to Diff 93987.Apr 3 2017, 7:03 PM
EricWF retitled this revision from [Sema] Add __is_aggregate type-trait and implement LWG 2015 to [Sema] Add __is_aggregate type-trait.
EricWF edited the summary of this revision. (Show Details)
  • Remove LWG 2015 implementation.
EricWF marked an inline comment as done.Apr 3 2017, 7:03 PM
This revision is now accepted and ready to land.Apr 4 2017, 5:11 AM
EricWF closed this revision.Apr 12 2017, 3:24 PM