From 27df656d6a5f598362f8b7d298f0c53f28a91d0f Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 3 Jun 2026 16:00:03 +0100 Subject: [PATCH] [spec/type] Specify the type of a template or template instance Remove typeof special case, as this is true outside typeof too. --- spec/type.dd | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/spec/type.dd b/spec/type.dd index 8deb793fcd14..781b42fb465f 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -741,6 +741,25 @@ $(H2 $(LNAME2 void, $(D void))) see $(RELATIVE_LINK2 pointer-conversions, Pointer Conversions). * $(DDSUBLINK spec/arrays, void_arrays, Void arrays). * $(DDSUBLINK spec/expression, cast_void, Ignoring a value) by casting to `void`. + * The type of a symbol resolving to a $(GLINK2 template, TemplateDeclaration). + * The type of a non-eponymous $(GLINK2 template, TemplateInstance). + + $(SPEC_RUNNABLE_EXAMPLE_COMPILE + -------------------- + void f(); + static assert(is(typeof(f()) == void)); + + void* ptr; + static assert(is(typeof(ptr[0]) == void)); + + template t() {} + static assert(is(typeof(t) == void)); + static assert(is(typeof(t!()) == void)); + -------------------- + ) + + $(RATIONALE To simplify the grammar, an expression can resolve to a template or + template instantiation. A valid expression must have a valid type.) $(P `void.sizeof` is 1 (not 0).) @@ -1020,15 +1039,6 @@ $(H3 $(LNAME2 typeof-special, Special Cases)) typeof(S.foo) n; // n is declared to be an int -------------------- - $(P If the expression is a $(DDLINK spec/template, Template, Template), - $(D typeof) gives the type $(D void). - ) - - -------------------- - template t {} - static assert(is(typeof(t) == void)); - -------------------- - $(H2 $(LNAME2 mixin_types, Mixin Types))