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

Douglas Gregor dgregor at apple.com
Thu Sep 9 13:40:29 PDT 2010


On Sep 9, 2010, at 11:29 AM, Chris Lattner wrote:

> 
> On Sep 9, 2010, at 9:55 AM, Luc Bourhis wrote:
> 
>> Hi,
>> 
>> consider the trivial source code
>> 
>> ==== warning.cpp ====
>> 
>> #pragma clang diagnostic push
>> #pragma clang diagnostic ignored "-Wtautological-compare"
>> 
>> unsigned foo(unsigned x) {
>> if (x < 0) return -x;
>> return x;
>> }
>> 
>> #pragma clang diagnostic pop
> ...
>> Is that the intended behaviour?
> 
> No, it's a bug.  A similar problem occurs with inline methods in classes:
> 
> class foo {
>  #pragma clang diagnostic push
>  #pragma clang diagnostic ignored "-Wtautological-compare"
> 
>  void bar() {
>    ...
>  }
> 
>  #pragma .. pop
> };
> 
> This is certainly a bug, but it's not trivial to fix.

FWIW, the fix would require us to keep track of the source ranges covering each push/pop. Then, when determining whether to suppress a diagnostic during template instantiation/inline member processing/etc., we would perform a binary search in those source ranges to determine the active pragmas, diagnostic flags, etc.

	- Doug



More information about the cfe-dev mailing list