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.
You just mean in unittests, right? It's useful (necessary?) elsewhere.
(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?
(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).
(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.
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/eb293b50638eda5e37c84be2f8e06a7cd22271f6 Fix issue 15320 https://github.com/D-Programming-Language/phobos/commit/7afe668428f19ba877e5d2d2dca0ca2ce1c315b0 Merge pull request #3807 from dcarp/Fix15320 [Issue 15320] eliminate 'static assert(__traits(compiles,..'
Commits pushed to stable at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/eb293b50638eda5e37c84be2f8e06a7cd22271f6 Fix issue 15320 https://github.com/D-Programming-Language/phobos/commit/7afe668428f19ba877e5d2d2dca0ca2ce1c315b0 Merge pull request #3807 from dcarp/Fix15320