title: C++ old-style cast warning on SIG_ERR
body: <p>While compiling some C++ code using <code>g++ (gcc version 4.2.1 20070719)</code> (OpenBSD 5.6 to be specific) with the <code>-Wold-style-cast</code> flag, I ran across an old-style cast warning for some signal handler code that I'm not sure where the cast is happening.</p>
  
  <p>MCVE:</p>
  
  <pre><code>// compile with g++ file.cpp -Wold-style-cast
  #include &lt;iostream&gt;
  #include &lt;csignal&gt;
  
  typedef void (*sighndlr)(int);
  
  void sig_handler(int sig)
  {
      std::cout &lt;&lt; "got sig: " &lt;&lt; sig &lt;&lt; std::endl;
  }
  
  int main(int argc, char* argv[])
  {
      // warning: use of old-style cast
      sighndlr sh = SIG_ERR;
  
      // warning: use of old-style cast
      void (*sigerr1)(int) = SIG_ERR;
  
      // warning: use of old-style cast
      void (*sigerr2)(int) = static_cast&lt;void(*)(int)&gt;(SIG_ERR);
  
      // warning: use of old-style cast
      void (*sigerr3)(int) = reinterpret_cast&lt;void(*)(int)&gt;(SIG_ERR);
  
      // warning: use of old-style cast
      if (std::signal(SIGABRT, sig_handler) == SIG_ERR) {
          std::cout &lt;&lt; "error install SIGABRT" &lt;&lt; std::endl;
      }
  
      // no errors or warnings
      if (std::signal(SIGTERM, sig_handler) == sigerr1) {
          std::cout &lt;&lt; "error install SIGTERM" &lt;&lt; std::endl;
      }
      // no errors or warnings
      std::signal(SIGSEGV, sig_handler);
  
      // This was just to confirm SIG_ERR wasn't some weird definition
      // error: invalid conversion from 'void (*)(int)' to 'void* (*)(int)'
      // void* (*e0)(int) = SIG_ERR;
      return 0;
  }
  </code></pre>
  
  <p>The warning isn't causing any issues and I figured for <code>void (*sigerr2)(int) = static_cast&lt;void(*)(int)&gt;(SIG_ERR)</code> it's on overly cautious parsing error on the part of the <code>-Wold-style-cast</code> flag, but I was more curious why it would give me a warning on <code>std::signal(SIGABRT, sig_handler) == SIG_ERR</code> and not on <code>std::signal(SIGTERM, sig_handler) == sigerr1</code>?</p>