#pragma GCC diagnostic push | pop

简介:
编译pg_shard时报了一个,是和GCC的特性有关的,
cc1: warnings being treated as errors
src/ruleutils_94.c:74: error: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
src/ruleutils_94.c:6549: error: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
make: *** [src/ruleutils_94.o] Error 1


src/ruleutils_94.c
出错在

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wswitch"


stackoverflow:
#pragma GCC diagnostic push and #pragma GCC diagnostic pop were added in gcc 4.6. You're using an older version.

These pragmas are typically used in conjunction with other #pragma GCC diagnostic directives to suppress, turn on, or turn into an error specific warnings for a small section of your code only. If they're ignored, the changes to warning levels will apply to the rest of the source file rather than just until the next #pragma GCC diagnostic pop. This may not be a problem, or it may be the end of the world; you'll need to understand your code to know for sure.

Either way, you should probably update your compiler. You wouldn't compile C99 with a C89 compiler; don't compile code containing pragmas for gcc 4.6 with gcc 4.4.

看样子现在CentOS 6.x 的GCC有点显老了,可以考虑升级gcc,但是牵涉较多。或者接下来可以考虑以CentOS 7.x为主了。

centos 7现在的gcc版本时4.8.3

# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.3/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) 

[参考]

6.61.11 Diagnostic Pragmas

GCC allows the user to selectively enable or disable certain types of diagnostics, and change the kind of the diagnostic. For example, a project's policy might require that all sources compile with -Werror but certain files might have exceptions allowing specific types of warnings. Or, a project might selectively enable diagnostics and treat them as errors depending on which preprocessor macros are defined.

#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.

kind is ‘error’ to treat this diagnostic as an error, ‘warning’ to treat it like a warning (even if -Werror is in effect), or ‘ignored’ if the diagnostic is to be ignored. option is a double quoted string that matches the command-line option.

          #pragma GCC diagnostic warning "-Wformat"
          #pragma GCC diagnostic error "-Wformat"
          #pragma GCC diagnostic ignored "-Wformat"

Note that these pragmas override any command-line options. GCC keeps track of the location of each pragma, and issues diagnostics according to the state as of that point in the source file. Thus, pragmas occurring after a line do not affect diagnostics caused by that line. 

#pragma GCC diagnostic push
#pragma GCC diagnostic pop
Causes GCC to remember the state of the diagnostics as of each  push, and restore to that point at each  pop. If a  pop has no matching  push, the command-line options are restored.
          #pragma GCC diagnostic error "-Wuninitialized"
            foo(a);                       /* error is given for this one */
          #pragma GCC diagnostic push
          #pragma GCC diagnostic ignored "-Wuninitialized"
            foo(b);                       /* no diagnostic for this one */
          #pragma GCC diagnostic pop
            foo(c);                       /* error is given for this one */
          #pragma GCC diagnostic pop
            foo(d);                       /* depends on command-line options */

GCC also offers a simple mechanism for printing messages during compilation.

#pragma message string
Prints string as a compiler message on compilation. The message is informational only, and is neither a compilation warning nor an error.
          #pragma message "Compiling " __FILE__ "..."

string may be parenthesized, and is printed with location information. For example,

          #define DO_PRAGMA(x) _Pragma (#x)
          #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
          
          TODO(Remember to fix this)

prints ‘/tmp/file.c:4: note: #pragma message: TODO - Remember to fix this’.

目录
相关文章
|
编译器 Linux 开发工具
|
NoSQL 编译器 开发工具
006.gcc编译器
gcc是什么?
232 0
006.gcc编译器
|
存储 NoSQL 算法
从一个crash问题展开,探索gcc编译优化细节
问题分析的过程也正是技术成长之路,本文以一个gcc编译优化引发的crash为切入点,逐步展开对编译器优化细节的探索之路,在分析过程中打开了新世界的大门……
|
前端开发 C语言
gcc动态库升级
gcc动态库升级
|
存储 编译器 C语言
深入理解GCC 和 G++ 编译器
GCC 和 G++ 是 GNU 工具链中的核心编译器,支持 C 和 C++ 程序开发。本文详细介绍其编译流程、常用选项及动态链接与静态链接的区别。编译过程分为预处理、编译、汇编和链接四个阶段,每个阶段有特定任务和命令选项。常用选项如 `-E`、`-S`、`-c` 和 `-o` 分别用于预处理、生成汇编代码、生成目标文件和指定输出文件。动态链接节省空间且易于更新,但依赖运行时库;静态链接独立高效,但文件较大且更新困难。合理选择优化选项(如 `-O0` 至 `-O3`)可提升程序性能。掌握这些知识有助于开发者更高效地编写、调试和优化代码。
深入理解GCC 和 G++ 编译器
|
编译器 Linux C语言
gcc的编译过程
GCC(GNU Compiler Collection)的编译过程主要包括四个阶段:预处理、编译、汇编和链接。预处理展开宏定义,编译将代码转换为汇编语言,汇编生成目标文件,链接将目标文件与库文件合并成可执行文件。
560 11
|
编译器 开发工具 C语言
Gcc 链接文件
Gcc 链接文件
234 4
|
编译器 C语言 C++
MinGW安装gcc
MinGW安装gcc
524 0
|
C语言
gcc的简易用法
【5月更文挑战第10天】gcc的简易用法。
217 8
|
C语言
gcc的简易用法(编译、参数与链接)
【5月更文挑战第14天】gcc的简易用法(编译、参数与链接)。
236 1