Bug 21711 – Concatenating a function pointer with a string should be an error

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-03-14T04:08:57Z
Last change time
2024-12-13T19:15:08Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
thomas.bockman
Moved to GitHub: dmd#19886 →

Comments

Comment #0 by thomas.bockman — 2021-03-14T04:08:57Z
Here's a weird bug (this works since 2.066.0): unittest { assert(is(typeof(cast(typeof({})) 91) == void function() pure @safe nothrow @nogc)); // This definitely should not pass, but does: assert((cast(typeof({})) 91) ~ "" == "["); } It becomes a compile-time error, as it should be, if the function pointer expression is replaced with a variable of the same type and value. (Reduced from an obfuscation puzzle posted on the forums: https://forum.dlang.org/post/[email protected])
Comment #1 by ag0aep6g — 2021-03-14T11:30:25Z
The issue seems to be that constant folding ignores the type. Test case without a function pointer: ---- void main() { immutable void* x = cast(void*) 91; string s = x ~ ""; /* accepted; should be rejected */ } ----
Comment #2 by robert.schadek — 2024-12-13T19:15:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19886 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB