(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).

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/305176

Title:
  [PR25509] can't disable __attribute__((warn_unused_result))

To manage notifications about this bug go to:
https://bugs.launchpad.net/glibc/+bug/305176/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to