Bug 15320 – static assert(__traits(compiles, xyz)) considered harmful in unittests

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-11T18:42:00Z
Last change time
2016-01-03T14:14:59Z
Assigned to
dragoscarp
Creator
andrei

Comments

Comment #0 by andrei — 2015-11-11T18:42:44Z
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.
Comment #1 by john.loughran.colvin — 2015-11-11T18:46:07Z
You just mean in unittests, right? It's useful (necessary?) elsewhere.
Comment #2 by andrei — 2015-11-11T20:16:59Z
(In reply to John Colvin from comment #1) > You just mean in unittests, right? It's useful (necessary?) elsewhere. Yah, unittests were the only use case I had in mind. What are others?
Comment #3 by john.loughran.colvin — 2015-11-12T11:22:34Z
(In reply to Andrei Alexandrescu from comment #2) > (In reply to John Colvin from comment #1) > > You just mean in unittests, right? It's useful (necessary?) elsewhere. > > Yah, unittests were the only use case I had in mind. What are others? template constraints, sanity checks, only way of implementing some template predicates (IIRC it appears quite a bit in std.range and std.traits for this).
Comment #4 by andrei — 2015-11-12T13:41:58Z
(In reply to John Colvin from comment #3) > (In reply to Andrei Alexandrescu from comment #2) > > (In reply to John Colvin from comment #1) > > > You just mean in unittests, right? It's useful (necessary?) elsewhere. > > > > Yah, unittests were the only use case I had in mind. What are others? > > template constraints, sanity checks, only way of implementing some template > predicates (IIRC it appears quite a bit in std.range and std.traits for > this). Nice. Yah, those would stay as they are.
Comment #5 by github-bugzilla — 2015-11-27T01:57:48Z
Comment #6 by github-bugzilla — 2016-01-03T14:14:59Z