On 09/23/2014 06:24 PM,
stephan.bergm...@googlemail.com wrote:
> The C standard mandates that the assert macro takes an argument of scalar type [7.2.1.1], and defines scalar types to be the collection of arithmetic and pointer types [6.2.5].
>
> The C++ standard delegates matters regarding to assert to the C standard without further ado [assertions].
>
> The C++ standard defines scalar types to be the collection of arithmetic types, enumeration types, pointer types, pointer to member types, std::nullptr_t, and cv-qualified versions of those [basic.types]. But presumably assert shall be restricted in C++ to the C-notion of scalar types? At least for scoped enumeration types it would not make sense to allow them as argument types to assert. But then again, for pointer to member types and std::nullptr_t it probably would?
>
> For non-scalar C++ types that have conversion functions to bool, should it be OK to use them as argument types to assert, or would that be non-portable at best?
> Specifically, the assert.h provided on Mac OS X expands to a use of GCC-specific __builtin_expect, taking a parameter of type long, so that with x of a type that only has an explicit conversion function to bool, assert(x) fails to compile. My current understanding is that that implementation is indeed allowed to reject that call.
I sort-of share your pain, but the pitfalls around assert() make me wonder
why I should invest effort into making it more C++-friendly.
(In particular, it's a macro, so side effects in its argument will vanish
when compiling with -DNDEBUG.)
Some dead horses are best left alone.
> However, it would feel more natural if for C++ assert were defined to take an argument that can be contextually converted to bool. Has this ever been discussed?
Not to my knowledge.
Jens