gcc 编译器警告标志缺失

gcc 编译器警告标志缺失

我想使用https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html。但是似乎我不能使用所有这些。例如,-Wpessimizing-movegcc 无法识别我(总是生成错误,因为此选项不存在)。这个问题存在于相当多的标志中。我使用来自 fedora 存储库的 gcc 这是我的版本输出:

Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Ziel: x86_64-redhat-linux
Konfiguriert mit: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread-Modell: posix
gcc-Version 8.3.1 20190223 (Red Hat 8.3.1-2) (GCC) 

gcc 和 g++ 都出现相同的错误。这种现象可能是什么原因造成的?如何解决?

答案1

文档明确指出这仅适用于 C++:

-Wpessimizing-move(仅适用于 C++)

所以g++会接受,但不是gcc

对于文档,可以检查相应的条目llvm-Wpessimizin-move

以下是一份副本:

此警告将捕获:

  • 使用 std::move 返回被移动的对象,其中移动的对象是局部变量
  • 在 pr-value 对象上使用 std::move

struct A {}  
A test() {  
    A a = std::move(A());  // warn since A() is a pr-value  
    return std::move(a);   // warn since a is a local variable  
}  

相关内容