C++ guys hate static_if?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 14 15:02:26 PDT 2013


On Thu, Mar 14, 2013 at 05:54:05PM -0400, Andrei Alexandrescu wrote:
> On 3/14/13 2:38 PM, Jonathan M Davis wrote:
> >On Thursday, March 14, 2013 13:26:18 Andrei Alexandrescu wrote:
> >>Walter has measured coverage of Phobos unittests a couple of times,
> >>it's very high. But I agree it would be nice to have it as a target.
> >
> >Though this is exactly a case where 100% unit test coverage doesn't
> >mean much.  All that means is that each path has been instantiated
> >and run. It doesn't mean that it's covered enough possible
> >instantiations to properly test the template.
> 
> Concepts won't help there either.
[...]

It does help. For example, if the code wrongly assumes mutability for a
particular template type, then it may work for most test cases (frankly,
I find const/immutable unittest coverage in Phobos very poor) but fail
when some daring user passes const(T) instead of T to the template. For
example, you may have accidentally written the equivalent of:

	auto func(T)(T t) {
		Unqual!T u = t; // <-- spot the bug
		...
	}

Under a concepts system, this would be caught early because the compiler
would detect a concept mismatch (Unqual!T != T) when analysing the
template code.

Currently, though, if there is no unittest that tries instantiating the
template with const(T), the bug goes undetected, because in all *tested*
instantiations, Unqual!T == T.


T

-- 
Famous last words: I wonder what will happen if I do *this*...


More information about the Digitalmars-d mailing list