Bug 2679 – Spurious "warning - " messages and erratic behaviour with is(typeof({void function}()))
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2009-02-20T15:13:00Z
Last change time
2014-03-01T00:36:01Z
Keywords
diagnostic, rejects-valid
Assigned to
bugzilla
Creator
andrei
Comments
Comment #0 by andrei — 2009-02-20T15:13:26Z
The following code outputs a "warning - " message during compilation:
template implicitlyConverts(S, T)
{
enum bool implicitlyConverts = T.sizeof >= S.sizeof
&& is(typeof({S s; T t = s;}()));
}
static assert(!implicitlyConverts!(long, short));
void main()
{
}
Comment #1 by smjg — 2009-02-21T15:45:19Z
There's something really fishy going on here.
----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>type bz2679a.d
bool valid = is(typeof({long s; short t = s;}()));
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -c bz2679a.d
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -w -c bz2679a.d
warning -
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>type bz2679b.d
static assert (is(typeof({long s; short t = s;}())));
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -c bz2679b.d
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -w -c bz2679b.d
warning - bz2679b.d(1): static assert is false
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>type bz2679c.d
static assert (!is(typeof({long s; short t = s;}())));
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -c bz2679c.d
bz2679c.d(1): static assert is false
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -w -c bz2679c.d
warning -
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>type bz2679d.d
pragma(msg, typeof({long s; short t = s;}()).stringof);
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -c bz2679d.d
void
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd -w -c bz2679d.d
warning - bz2679d.d(1): Error: implicit conversion of expression (s) of type lon
g to short can cause loss of data
void
----------
Not only is it spitting out that message, but the diagnosed validity of the expression inside the typeof seems to depend on a few things. Really, the expression is valid, but when warnings are enabled it gets mixed up. Tested on both 1.040 and 2.025 (Windows) with same effect.