Bug 16175 – allow statements and declaration in a compiles block

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-06-15T10:00:01Z
Last change time
2022-11-09T14:56:38Z
Assigned to
No Owner
Creator
Seb

Comments

Comment #0 by greensunny12 — 2016-06-15T10:00:01Z
it would be sometimes nice to be able to use expressions and statements inside the compiles block: ``` int c = 5; static assert(!__traits(compiles,int* cMutable = &c)); ``` I understand if the rationale was to keep `compiles` simple, because most things can be done with expressions. Anyway, e.g. for teaching this is quite nice: https://github.com/stonemaster/dlang-tour/pull/144
Comment #1 by ketmar — 2016-06-15T12:16:12Z
actually, most of the time you can do that with this: __traits(compiles,{int* cMutable = &c;}) just use lambda syntax -- we have many of 'em in D. ;-)
Comment #2 by razvan.nitu1305 — 2022-11-09T14:56:38Z
Yes, it works, you just need to use a block statement.