2015-02-12 4 views
3

Я заметил, что только некоторые предупреждения поддерживаются диагностической прагмой GCC.Почему диагностическая прагма GCC не работает для некоторых типов предупреждений?

это работает:

#pragma GCC diagnostic error "-Wconversion" 

это не удается:

#pragma GCC diagnostic error "-Wframe-larger-than=32" 

... с ошибкой:

error: unknown option after '#pragma GCC diagnostic' kind [-Werror=pragmas] 
#pragma GCC diagnostic error "-Wframe-larger-than" 

..both этих аргументов работать с GCC, когда передается как аргументы командной строки.


Есть ли документация, какие предупреждения поддерживаются GCC diagnostic прагме?

ответ

3

Я подозреваю, что вы обнаружили ошибку в GCC для этой конкретной опции.

С Следующий простой пример (см это live):

#include <stdio.h> 

int main(void) 
{ 
    int i = 4; 

    printf("%d\n", i); 

    return 0; 
} 

, который собран с -Wframe-larger-than=2 есть явно предупреждение:

warning: the frame size of 16 bytes is larger than 2 bytes [-Wframe-larger-than=]

Однако с комбинацией -Werror= (т.е. полный флаг -Werror=frame-larger-than=2), он ведет себя странным образом:

error: the frame size of 16 bytes is larger than 1 bytes [-Werror=frame-larger-than=]

Что еще более странно, что он выглядит, что значение полностью игнорируется , поскольку -Werror=frame-larger-than=64 до сих пор производит ту же самую ошибку, несмотря на то что значение Treshold выполняется (т.е. 16 < 64)

(примечание стороны: GCC версии 4.9.0)

Я считаю, что обработка -Werror= вариант как-то связано с #pragma GCC diagnostic error, следующим образом, кажется, работает:

#include <stdio.h> 

#pragma GCC diagnostic error "-Wframe-larger-than=" 
int main(void) 
{ 
    int i = 4; 

    printf("%d\n", i); 

    return 0; 
} 

возвращая ошибка как:

error: the frame size of 16 bytes is larger than 1 bytes [-Werror=frame-larger-than=]

но отказывается сотрудничать с любым значением, например:

#pragma GCC diagnostic error "-Wframe-larger-than=2" 

производит:

warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]

3

Это лучшее, что я нашел:
GCC руководство по this:

pragma GCC diagnostic kind option:
Modifies the disposition of a diagnostic. Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W...’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.

и GCC руководство по this:

Right now, only the C++ front end can honor these options.
....
-fdiagnostics-show-option:
This option instructs the diagnostic machinery to add text to each diagnostic emitted, which indicates which command line option directly controls that diagnostic, when such an option is known to the diagnostic machinery.