[Issue 15320] New: static assert(__traits(compiles, xys)) considered harmful
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Nov 11 10:42:44 PST 2015
https://issues.dlang.org/show_bug.cgi?id=15320
Issue ID: 15320
Summary: static assert(__traits(compiles, xys)) considered
harmful
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
The pattern `static assert(__traits(compiles, xyz))` arised probably as a
converse to its negation, e.g.:
static assert( __traits(compiles, emplace(&ss2)));
static assert(!__traits(compiles, emplace(&ss2, SS2.init)));
However, the pattern should be avoided for two reasons:
1. Often it's best to also execute the code and make sure it works as expected
2. When working on the module, a failure of `static assert(__compiles)` does
not show the reason in the error messages. This makes code more difficult to
work with gratuitously.
We should eliminate this pattern from all of Phobos.
--
More information about the Digitalmars-d-bugs
mailing list