Issue 15241 - struct literal implicitly converts void* to size_t
Summary: struct literal implicitly converts void* to size_t
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL: http://dpaste.dzfl.pl/6001f46873fd
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2015-10-23 09:38 UTC by Cauterite
Modified: 2024-11-24 20:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Cauterite 2015-10-23 09:38:22 UTC
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 Cauterite 2015-10-23 09:42:27 UTC
Related: http://dpaste.dzfl.pl/68de69a294c3
Comment 2 Nick Treleaven 2024-11-24 20:16:55 UTC
(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.