Skip to content

Commit f813034

Browse files
committed
fix Issue 21585 - add __traits(totype, string)
1 parent 2298fc2 commit f813034

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/traits.dd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ $(GNAME TraitsKeyword):
7575
$(GLINK derivedMembers)
7676
$(GLINK isSame)
7777
$(GLINK compiles)
78+
$(GLINK toType)
7879

7980
$(GNAME TraitsArguments):
8081
$(GLINK TraitsArgument)
@@ -1663,6 +1664,27 @@ void main()
16631664
partial specialization allows for.)
16641665
)
16651666

1667+
$(H2 $(GNAME toType))
1668+
1669+
$(P Takes a single argument, which must evaluate to an expression of type `string`.
1670+
The contents of the string must correspond to the $(DDSUBLINK abi, name_mangling, mangled contents of a type)
1671+
that has been seen by the implementation.)
1672+
1673+
$(P Only D mangling is supported. Other manglings, such as C++ mangling, are not.)
1674+
1675+
$(P The value returned is a type.)
1676+
1677+
---
1678+
template Type(T) { alias Type = T; }
1679+
1680+
Type!(__traits(toType, "i")) j = 3; // j is declared as type `int`
1681+
1682+
static assert(is(Type!(__traits(toType, (int*).mangleof)) == int*));
1683+
1684+
__traits(toType, "i") x = 4; // x is also declared as type `int`
1685+
---
1686+
1687+
$(RATIONALE Provides the inverse operation of the $(DDSUBLINK property, mangleof, `.mangleof`) property.)
16661688

16671689

16681690
$(SPEC_SUBNAV_PREV_NEXT version, Conditional Compilation, errors, Error Handling)

0 commit comments

Comments
 (0)