title: Is there a way to use GCC __attribute__((noreturn)) and <stdnoreturn.h> sanely in a single translation unit?
body: <p>In C11, there is the keyword <code>_Noreturn</code> which is a function specifier (like <code>inline</code> is) that indicates the function does not return — it calls <code>exit()</code> or equivalent.  There is also a header, <code>&lt;stdnoreturn.h&gt;</code>, the complete definition for which is:</p>
  
  <blockquote>
    <h3>7.23 <code>_Noreturn &lt;stdnoreturn.h&gt;</code></h3>
    
    <p>¶1 The header <code>&lt;stdnoreturn.h&gt;</code> defines the macro</p>
  
  <pre><code>noreturn
  </code></pre>
    
    <p>which expands to <code>_Noreturn</code>.</p>
  </blockquote>
  
  <p>In GNU C (GCC), there is an attribute <code>__attribute__((noreturn))</code> that does essentially the same job.  One difference is that <code>__attribute__((noreturn))</code> can appear before or after the function declarator:</p>
  
  <pre><code>extern __attribute__((noreturn)) void err_error(const char *format, ...);
  extern void err_error(const char *format, ...) __attribute__((noreturn));
  </code></pre>
  
  <p>The problem is that if you include <code>&lt;stdnoreturn.h&gt;</code> in a translation unit (TU), any subsequent uses of <code>__attribute__((noreturn))</code> get mapped to <code>__attribute__((_Noreturn))</code> which then causes the compilation to fail because the attribute <code>_Noreturn</code> is not recognized (even though the keyword is recognized as a keyword).  That is, as far as I can tell, you cannot use both systems at once.</p>
  
  <ul>
  <li><p>Is there any way around this problem other than either:</p>
  
  <ol>
  <li>a big-bang migration of all code using the attribute to use <code>&lt;stdnoreturn.h&gt;</code>, or</li>
  <li>using the less-than-entirely-graceful <code>_Noreturn</code> keyword?</li>
  </ol></li>
  </ul>
  
  <p>You can detect C11 by testing <code>__STDC_VERSION__ &gt;= 201112L</code> — the value was specified by Technical Corrigendum 1 because the standard accidentally left the value incompletely specified:</p>
  
  <blockquote>
    <p><code>__STDC_VERSION__</code> The integer constant <em>201ymmL</em>.<sup>178)</sup></p>
    
    <p><sup>178)</sup> This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in
    ISO/IEC 9899:1990/Amd.1:1995 and as 199901L in ISO/IEC 9899:1999. The intention is that this
    will remain an integer constant of type <code>long int</code> that is increased with each revision of this
    International Standard.</p>
  </blockquote>
  
  <p>This can be used to condition the treatment in any one header file, but if you have a mixture of modified and unmodified (C11 and C99) headers, I seem to be running into intractable problems with <code>&lt;stdnoreturn.h&gt;</code>.</p>
  
  <ul>
  <li>Is it worth filing a bug with GCC to request that <code>__attribute__((_Noreturn))</code> be made into a synonym for <code>__attribute__((noreturn))</code> — which would resolve the problem.</li>
  </ul>