(In reply to Paul Pluzhnikov from comment #28)
> Well, that did expose the 30 bugs above, but unfortunately I can't do that
> permanently, because it also exposed this false positive:
>
> assert(v.empty());
>
> where assert in NDEBUG mode expanded into
>
> static_cast<void>(v.empty());
Isn't assert in NDEBUG mode guaranteed to not evaluate its argument? The above seems to violate that assumption.
In C++ you could do this:
template<typename T>
inline T ignore_result(T x __attribute__((unused)))
{
return x;
}
extern int foo() __attribute__((warn_unused_result));
int main()
{
ignore_result(foo());
return 0;
}
Another alternative is to use #pragma GCC diagnostics push/ignored/pop. Ideally you could encapsulate that into a macro "ignore_result", but #pragma diagnostics does not work well in a macro definition yet (I cannot remember the PR number for this).
(In reply to Paul Pluzhnikov from comment #28) cast<void> (v.empty( ));
> Well, that did expose the 30 bugs above, but unfortunately I can't do that
> permanently, because it also exposed this false positive:
>
> assert(v.empty());
>
> where assert in NDEBUG mode expanded into
>
> static_
Isn't assert in NDEBUG mode guaranteed to not evaluate its argument? The above seems to violate that assumption.
In C++ you could do this:
template<typename T> _((unused) )) _((warn_ unused_ result) );
inline T ignore_result(T x __attribute_
{
return x;
}
extern int foo() __attribute_
int main() result( foo());
{
ignore_
return 0;
}
Another alternative is to use #pragma GCC diagnostics push/ignored/pop. Ideally you could encapsulate that into a macro "ignore_result", but #pragma diagnostics does not work well in a macro definition yet (I cannot remember the PR number for this).