GCC:使用-pedantic时是否可以禁用“枚举器列表末尾的逗号”警告?

时间:2020-12-18 06:59:20

I'm compiling C++ code and I'd like to enable the -pedantic option.
I'm using GCC 4.0, running Xcode on Mac OS X Leopard.
It is for example possible to allow variadic macros and the long long type that are normally forbidden when using -pedantic (with -Wno-variadic-macros and -Wno-long-long). But I could not find anything to disable the "comma at end of enumerator list" warning.
Is it possible?

我正在编译C ++代码,我想启用-pedantic选项。我正在使用GCC 4.0,在Mac OS X Leopard上运行Xcode。例如,允许使用-pedantic(带-Wno-variadic-macros和-Wno-long-long)时通常禁止的可变宏和long long类型。但我找不到任何禁用“枚举器列表末尾的逗号”警告的内容。可能吗?

Thanks.

2 个解决方案

#1


A comma at the end of an enumerator is valid in C99 but not in C89, so the following will work providing your code is valid C99

枚举器末尾的逗号在C99中有效但在C89中无效,因此如果您的代码有效,则以下内容将起作用

gcc -std=c99 -pedantic foo.c

I'm fairly sure that it's not valid in C++ (according to g++) at all

我很确定它在C ++中无效(根据g ++)

Edit: tested this with GCC 4.2.1 on HP-UX and it works with no errors / warnings foo.c

编辑:在HP-UX上使用GCC 4.2.1进行测试,并且没有错误/警告foo.c

int main(int argc, char** argv) {
    enum { A, B, };
    return 0;
}


gcc -std=c99 -pedantic foo.c

#2


In C++ it is not yet possible to disable it, even though it legal in C++11. So in the future, when GCC is corrected, -std=c++11 should disable it.

在C ++中,即使它在C ++ 11中合法,也无法禁用它。所以在将来,当GCC得到纠正时,-std = c ++ 11应该禁用它。

-std=c99 only works in C, not C++ (as in the question).

-std = c99仅适用于C,而不适用于C ++(如问题中所述)。

#1


A comma at the end of an enumerator is valid in C99 but not in C89, so the following will work providing your code is valid C99

枚举器末尾的逗号在C99中有效但在C89中无效,因此如果您的代码有效,则以下内容将起作用

gcc -std=c99 -pedantic foo.c

I'm fairly sure that it's not valid in C++ (according to g++) at all

我很确定它在C ++中无效(根据g ++)

Edit: tested this with GCC 4.2.1 on HP-UX and it works with no errors / warnings foo.c

编辑:在HP-UX上使用GCC 4.2.1进行测试,并且没有错误/警告foo.c

int main(int argc, char** argv) {
    enum { A, B, };
    return 0;
}


gcc -std=c99 -pedantic foo.c

#2


In C++ it is not yet possible to disable it, even though it legal in C++11. So in the future, when GCC is corrected, -std=c++11 should disable it.

在C ++中,即使它在C ++ 11中合法,也无法禁用它。所以在将来,当GCC得到纠正时,-std = c ++ 11应该禁用它。

-std=c99 only works in C, not C++ (as in the question).

-std = c99仅适用于C,而不适用于C ++(如问题中所述)。