Note that there are some explanatory texts on larger screens.

plurals
  1. POCompile time optimization - removing debug prints from release binaries
    primarykey
    data
    text
    <p>It is my very first post, so I would like to welcome with everybody. The problem I have occurred is the code optimization at compilation time, and to be more specific removing debug prints.</p> <p>Let's imagine that we have native <code>syslog logger</code> and we are wrapping it (without using of macros, it is very important note!) with following code:</p> <pre><code>enum severity { info_log, debug_log, warning_log, error_log }; template &lt;severity S&gt; struct flusher { logger* log_; flusher(logger* log) : log_(log) {} flusher(flusher&amp; rhs) : log_(rhs.log_) {} ~flusher() { syslog(S, log_-&gt;stream.str()); log_-&gt;stream.str(""); } operator std::ostream&amp; () { return log_-&gt;stream; } }; #ifdef NDEBUG template &lt;&gt; struct flusher&lt;debug_log&gt; { flusher(logger*) {} flusher(flusher&amp;) {} ~flusher() {} template &lt;typename T&gt; flusher&amp; operator&lt;&lt;(T const&amp;) { return *this; } }; #endif struct logger { std::ostringstream stream; template &lt;severity T&gt; flusher&lt;T&gt; operator&lt;&lt;(flusher&lt;T&gt; (*m)(logger&amp;)) { return m(*this); } }; inline flusher&lt;info_log&gt; info(logger&amp; log) { return flusher&lt;info_log&gt;(&amp;log); } inline flusher&lt;debug_log&gt; debug(logger&amp; log) { return flusher&lt;debug_log&gt;(&amp;log); } inline flusher&lt;warning_log&gt; warning(logger&amp; log) { return flusher&lt;warning_log&gt;(&amp;log); } inline flusher&lt;error_log&gt; error(logger&amp; log) { return flusher&lt;error_log&gt;(&amp;log); } </code></pre> <p>I thought that the empty implementation of flusher will encourage compiler to remove such useless code, but with both <code>O2</code> and <code>O3</code> it is not removed. </p> <p>Is there any possibility to provoke mentioned behaviour?</p> <p>Thanks in advance </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload