[Issue 3750] Template specialization based on shared doesn't seem to work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 18 23:03:19 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=3750

ag0aep6g <ag0aep6g at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |ag0aep6g at gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #1 from ag0aep6g <ag0aep6g at gmail.com> ---
(In reply to Jason House from comment #0)
> Example #1:
> template foo( T U == shared ){ enum U foo = 1; }
> static assert(is(foo!(shared int) == int));

This example is invalid.

Template specialization syntax doesn't use `==`. It uses `:`. And there is no
form with two identifiers on the left hand side. That's `is` expression syntax.


> Example #2:
> template foo( T ) if (is(T U == shared)){ enum U foo = 1; }
> static assert(is(foo!(shared int) == int));
[...]
> Example #3:
> template foo( T ) if (is(T U == shared)){ enum U foo = 1; }
> pgragma(msg, foo!(shared int));

Ignoring minor mistakes, these examples show that `is` expressions in template
constraints don't propagate their newly defined aliases into the template body.
Issue 6269 is dedicatead to that.


> ... although this example (incomplete) fails:
>         template isValidNumericType( T )
>         {
>           static if (is(T U == shared)){
>             enum bool isValidNumericType = isIntegerType!( U ) ||
>                                            isPointerType!( U );
>           }
>           else
>           {
>             enum bool isValidNumericType = isIntegerType!( T ) ||
>                                            isPointerType!( T );
>           }
>         }
> -----------------------------------------
> tango/core/Atomic.d(828): Error: static assert
> (isValidNumericType!(shared(int))) is false

Works for me when isIntegerType and isPointerType are defined as follows:

    template isIntegerType(T) { enum isIntegerType = is(T : ulong); }
    template isPointerType(T) { enum isPointerType = is(T : void*); }


Examples #2 and #3 seem to be the only valid ones, and the underlying issue is
better described in issue 6269. So I'm closing this as a duplicate.

*** This issue has been marked as a duplicate of issue 6269 ***

--


More information about the Digitalmars-d-bugs mailing list