title: How to ignore warnings in headers that are part of a clang C++ module?
body: <p>We're using clang with <code>-fmodule</code> and <code>-fcxx-module</code> to enable module support as documented at <a href="http://clang.llvm.org/docs/Modules.html" rel="noreferrer">http://clang.llvm.org/docs/Modules.html</a>. We're already seeing a significant improvement in build times by defining module maps for our core libraries.</p>
  
  <p>However, we have some library headers that use pragmas to disable warnings for certain lines, for example:</p>
  
  <pre><code>template &lt;typename TFloat&gt;
  static bool exactlyEqual(TFloat lhs, TFloat rhs)
  {
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wfloat-equal"
      return lhs == rhs;
  #pragma clang diagnostic pop
  }
  </code></pre>
  
  <p>When this header is pulled in as a precompiled module, it seems clang's internal representation does not preserve the pragma information and the warning is still emitted. Since we treat warnings as errors this causes compilation to fail. Some might argue to just disable <code>float-equal</code> entirely, but we have a bunch of other cases with different warnings which we don't want to globally disable.</p>
  
  <p>We're already using <code>-Wno-system-headers</code> and <code>-isystem</code> so that clients of libraries generally don't see warnings like this anyway (even without the pragma), but this doesn't seem to work when the header is imported as a module. In addition we still hit these warnings for code internal to the library which includes the header as a non-system header (i.e. without using <code>-isystem</code> / using double quotes), since module precompilation and importing also occurs here.</p>
  
  <p>I've tried using <code>_Pragma(...)</code> instead of <code>#pragma</code> which didn't have any effect.</p>
  
  <p>Is there some other way to conditionally ignore warnings in headers that come from precompiled clang modules?</p>
  
  <p><strong>UPDATE:</strong> I've put a sample project up on <a href="https://github.com/MikeWeller/ClangModuleWarnings" rel="noreferrer">https://github.com/MikeWeller/ClangModuleWarnings</a> which reproduces the problem</p>
  
  <p><strong>UPDATE:</strong> Seems the <code>[system]</code> module attribute will suppress all warnings. However this suppresses even warnings we want to see when building the library itself, and we don't want to make all our modules system modules. If we find a way to not use the library's module map when building the library itself this may be acceptable but we'd still like to pragma out certain warnings for non-system modules..</p>