Bug 15437 – documentation for typeof(someTemplate) == void

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-12T23:58:16Z
Last change time
2022-02-15T02:10:01Z
Keywords
preapproved, pull, trivial
Assigned to
No Owner
Creator
Luís Marques

Comments

Comment #0 by luis — 2015-12-12T23:58:16Z
Consider this: auto tee(alias fun, Flag!"pipeOnPop" pipeOnPop = Yes.pipeOnPop, R1)(R1 inputRange) if (is(typeof(fun) == void) || isSomeFunction!fun); It is not immediately obvious in what situation `fun` would have (typeof(fun) == void) unless you know that templates received through an alias have typeof void, but there doesn't seem to be any place in the documentation mentioning that fact. Even if this is mentioned in the docs somewhere, it might still be worth redundantly mentioning this in more than one place. Consider the sections on AliasDeclaration and typeof (part of the declaration docs), and the Template docs.
Comment #1 by dfj1esp02 — 2015-12-14T11:55:57Z
IIRC, typeof(fun) gives the function's return type.
Comment #2 by luis — 2015-12-14T12:29:16Z
But if it is a function *template* then the type will be void. That's what could be better documented, IMHO.
Comment #3 by dfj1esp02 — 2015-12-14T13:44:51Z
Maybe it's not an intended behavior and type of template should be `template`?
Comment #4 by petar.p.kirov — 2015-12-14T13:48:27Z
Maybe something like this: T add(T)(T a, T b) { return a + b; } static assert (is(typeof(add) == template)); alias add2 = (a,b) => a + b; static assert (is(typeof(add2) == template)); ?
Comment #5 by petar.p.kirov — 2015-12-14T13:51:54Z
Though this would add overlap to the functionality already provided by http://dlang.org/spec/traits.html#isTemplate. Also related: https://github.com/D-Programming-Language/dmd/pull/5201
Comment #6 by johannes.loher — 2018-05-05T22:44:31Z
Related: https://issues.dlang.org/show_bug.cgi?id=7947 I briefly talked to both Andrei and Walter today at dconf about this. They both agreed, that calling typeof on a template should be an error (similiar to how calling typeof on a type is an error). Any thoughts on that?
Comment #7 by andrei — 2018-05-05T23:18:10Z
preapproved
Comment #8 by johannes.loher — 2018-05-05T23:31:56Z
Realated comment in the corresponding section in dmd: /* Today, 'typeof(func)' returns void if func is a * function template (TemplateExp), or * template lambda (FuncExp). * It's actually used in Phobos as an idiom, to branch code for * template functions. */ Does anybody know where this is actually used in phobos? Wouldn't it be better to use isTemplate in this case?
Comment #9 by dlang-bot — 2022-02-14T18:15:17Z
@pbackus created dlang/dlang.org pull request #3218 "Fix issue 15437 - documentation for typeof(someTemplate) == void" fixing this issue: - Fix issue 15437 - documentation for typeof(someTemplate) == void https://github.com/dlang/dlang.org/pull/3218
Comment #10 by dlang-bot — 2022-02-15T02:10:01Z
dlang/dlang.org pull request #3218 "Fix issue 15437 - documentation for typeof(someTemplate) == void" was merged into master: - 5d5764f978d32dadaeed12afe3dd26992b822b9d by Paul Backus: Fix issue 15437 - documentation for typeof(someTemplate) == void https://github.com/dlang/dlang.org/pull/3218