Bug 15241 – struct literal implicitly converts void* to size_t

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2015-10-23T09:38:22Z
Last change time
2024-11-24T20:16:55Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Cauterite

Comments

Comment #0 by cauterite — 2015-10-23T09:38:22Z
http://dpaste.dzfl.pl/6001f46873fd On my 32-bit x86 system (DMD v2.068.2), the results are slightly different from dpaste's compiler: struct HandleT { size_t Val; }; void main() { auto h1 = HandleT( cast(const void*) 1 ); // allowed auto h2 = HandleT( cast(void*) 1 ); // allowed auto p1 = cast(const void*) 1; auto h3 = HandleT( p1 ); // allowed auto p2 = cast(void*) 1; auto h4 = HandleT( p2 ); // rejected }; const(void*) is allowed but void* is rejected O.o Obviously none of these expressions should compile.
Comment #1 by cauterite — 2015-10-23T09:42:27Z
Comment #2 by nick — 2024-11-24T20:16:55Z
(In reply to Cauterite from comment #0) > auto p1 = cast(const void*) 1; > auto h3 = HandleT( p1 ); // allowed This was disallowed by the time of v2.068.2. onlineapp.d(11): Error: cannot implicitly convert expression `cast(const(void*))cast(size_t)1LU` of type `const(void*)` to `ulong` > Related: http://dpaste.dzfl.pl/68de69a294c3 Server not responding.