title: -Werror=format: how can the compiler know
body: <p>I wrote this intentionally wrong code</p>
  
  <pre><code>printf("%d %d", 1);
  </code></pre>
  
  <p>compiling with <code>g++</code> and <code>-Werror=format</code>.</p>
  
  <p>The compiler gives this very impressive warning:</p>
  
  <pre><code>error: format '%d' expects a matching 'int' argument [-Werror=format]
  </code></pre>
  
  <p>As far as I can see, there's no way the compiler can tell that the code is wrong, because the format string isn't parsed until runtime.</p>
  
  <p>My question: does the compiler have a special feature that kicks in for printf and similar libc functions, or is this a feature I could use for my own functions? String literals?</p>