[Issue 24875] New: std.traits.isAggregateType does not consider enums of aggregate types to be aggregate types
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 23 12:19:12 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24875
Issue ID: 24875
Summary: std.traits.isAggregateType does not consider enums of
aggregate types to be aggregate types
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: issues.dlang at jmdavisProg.com
The second assertion fails:
---
import std.traits;
struct S {}
enum ES : S { a = S.init }
static assert( isAggregateType!S);
static assert( isAggregateType!ES);
---
Looking at std.traits.isAggregateType, it does not take enums into account, and
the kind of code that tests for whether a type is an aggregate type is almost
certainly going to want to consider enums whose base type is an aggregate type
as an aggregate type, meaning that right now, the correct way to use
isAggregateType is almost certainly going to be
isAggregateType!(OriginalType!T)), which I'm guessing almost no code does.
This likely has not come up previously either due to the fact that
isAggregateType almost certainly isn't needed very often - or due to the fact
that enums whose base type is an aggregate type seem to be quite rare in D
(many people seem to not know that you even _can_ do it).
But from what I can tell, there really isn't a good reason not to consider an
enum with a base type that's an aggregate type as an aggregate type, and most
people are not going to think of enums possibly being an aggregate type,
meaning that while the current situation arguably is not actually a bug, it
certainly makes it easy to introduce bugs.
Fortunately, I'm pretty sure that this is the kind of change that we can make
without breaking code, and it might actually fix some subtle bugs in Phobos
related to the few places that use isAggregateType.
--
More information about the Digitalmars-d-bugs
mailing list