D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16175 - allow statements and declaration in a compiles block
Summary: allow statements and declaration in a compiles block
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-15 10:00 UTC by Seb
Modified: 2022-11-09 14:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Seb 2016-06-15 10:00:01 UTC
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 Ketmar Dark 2016-06-15 12:16:12 UTC
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 RazvanN 2022-11-09 14:56:38 UTC
Yes, it works, you just need to use a block statement.