[cfe-dev] Pragma warning control

Sebastian Redl sebastian.redl at getdesigned.at
Sat Jan 10 03:54:22 PST 2009


me22 wrote:
> On Fri, Jan 9, 2009 at 17:52, Sebastian Redl
> <sebastian.redl at getdesigned.at> wrote:
>   
>> I'm thinking of implementing a pragma to control Clang warnings. This
>> would look something like this (borrowing MS syntax because it makes
>> sense, IMO):
>>
>> struct A;
>>
>> void f(A *a) {
>> #pragma Clang warning(disable: warn_delete_incomplete)
>>  // This would cause the warning, but I know it to be safe:
>>  delete a;
>>  // Bring warning back to its default status so that real issues aren't
>> missed.
>> #pragma Clang warning(default: warn_delete_incomplete)
>> }
>>
>>     
>
> I think something like this would be better:
>
>  void f(A *a) {
>   #pragma Clang warning(--warn_delete_incomplete)
>    delete a;
>   #pragma Clang warning(++warn_delete_incomplete)
>  }
>
>   

So basically, you have a counter that is initialized to 0 if the warning
is disabled, and 1 if it's enabled, and the warning is emitted if its
counter is >= 1?
Interesting idea, but I think this would give users trying to reliably
disable warnings a headache - you'd find something like

// Just in case someone enabled the warning when it was already enabled:
#pragma Clang warning(--warn_delete_incomplete)
#pragma Clang warning(--warn_delete_incomplete)

I think supporting warning(push) and warning(pop) is the better
technique here. This allows proper nesting with headers.

> Be nice for things like gcc's strict aliasing warnings, too.  The
> build could default to the stricter, false-positive including mode,
> and it could be lowered to the only false negatives mode in sections
> of the code that need it.
>   
Aren't strict and weak mode different warnings? The Clang diagnostic
system certainly doesn't support different warning strictness levels.

Sebastian



More information about the cfe-dev mailing list