Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-04-06 07:20:17

John Maddock wrote:

>> So the __noreturn__ command used by GNU's /usr/include/assert.h couldn't
>> be
>> used?
>> /* This prints an "Assertion failed" message and aborts. */
>> extern void __assert_fail (__const char *__assertion, __const char
>> *__file,
>> unsigned int __line, __const char *__function)
>> __THROW __attribute__ ((__noreturn__));
> Wouldn't that have to be applied to your function signature, rather than
> the assertion?

Well, code like this doesn't trigger a warning when compiled with g++

$ cat trial.cpp
#include <cassert>

int foo(bool a) {
        if (a)
                return 0;

$ g++ -W -Wall -c trial.cpp

Compare that with:

$ g++ -DNDEBUG -W -Wall -c trial.cpp
trial.cpp: In function `int foo(bool)':
trial.cpp:7: warning: control reaches end of non-void function

Clearly, the compiler is able to ascertain that execution won't proceed
past the assert. It doesn't seem so unreasonable to hope that
BOOST_STATIC_ASSERT would behave similarly.


Boost list run by bdawes at, gregod at, cpdaniel at, john at