Counter intuitively, asserts hurt gcc static dataflow analysis.

David Brown david@westcontrol.com
Fri May 11 06:21:00 GMT 2018



On 10/05/18 00:30, John Carter wrote:

> It catches things that can be inlined but seen as constant at comile time.
> 
> I think as gcc's optimizer get's smarter this will be quite a win.
> 
> It also basically subsumes static_assert()

This does not replace static_assert.  The key point about static_assert 
is that it is /always/ static - zero cost at run-time or code size.  You 
know that is the case when you write it, and other people reading the 
code know that.  So static_asserts are always free, and can be used 
liberally.  With an assert() modified to give compile-time warnings when 
possible, you will generally have run-time costs.





More information about the Gcc-help mailing list