[cfe-dev] #pragma diagnostic ignored and template code

Luc Bourhis luc_j_bourhis at mac.com
Thu Sep 9 10:20:09 PDT 2010


I cat and then pasted the wrong code, sorry!

> Hi,
> 
> consider the trivial source code
> 
==== warning.hpp ====

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"

template <class T>
T foo(T x) {
  if (x < T(0)) return -x;
  return x;
}

#pragma clang diagnostic pop

> 
> ==== main.cpp ====
> 
> #include "warning.hpp"
> #include <iostream>
> 
> int main() {
>  std::cout << foo(1u) << std::endl;
>  return 0;
> }
> 
> ================
> 
> clang ignores the #pragma's completely:
> 
> ~> clang++ -o main main.cpp        
> In file included from main.cpp:1:
> ./warning.hpp:6:9: warning: comparison of unsigned expression < 0 is always false
>      [-Wtautological-compare]
>  if (x < T(0)) return -x;
>      ~ ^ ~~~~
> main.cpp:5:16: note: in instantiation of function template specialization 'foo<unsigned int>' requested
>      here
>  std::cout << foo(1u) << std::endl;
>               ^
> 1 warning generated.
> 
> 
> Is that the intended behaviour?
> 
> Luc Bourhis
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100909/5d9acb02/attachment.bin>


More information about the cfe-dev mailing list