不应该clang从/ usr / local / include中的头文件中禁止警告吗?

问题描述 投票:3回答:1

我正在OSX上构建一个使用Boost.Log的应用程序。当我将警告标志设置为包含-Wextra时,我会在其中一个Boost头文件中收到有关未使用参数的警告。

MWE:

#include <boost/log/trivial.hpp>

int main() {
  BOOST_LOG_TRIVIAL(error) << "no log";
  return 0;
}

保存为nolog.cpp,然后编译:

c++ -Wextra -DBOOST_LOG_DYN_LINK -o nolog -lboost_log-mt nolog.cpp

我看到以下错误:

In file included from nolog.cpp:1:
In file included from /usr/local/include/boost/log/trivial.hpp:23:
In file included from /usr/local/include/boost/log/sources/record_ostream.hpp:36:
In file included from /usr/local/include/boost/log/utility/formatting_ostream.hpp:30:
/usr/local/include/boost/log/detail/attachable_sstream_buf.hpp:284:67: warning: unused parameter 'n' [-Wunused-parameter]
    size_type length_until_boundary(const char_type* s, size_type n, size_type max_size, mpl::true_) const
                                                                  ^
1 warning generated.

我本以为/usr/local/include中的任何东西都会被视为系统标题,因此它的警告被抑制,但显然不是。

我也试过添加--system-header-prefix /usr/local/include,但这没有什么区别。

UPDATE

按照@ KompjoeFriek的建议,这里是-###的输出:

$ c++ -Wextra -DBOOST_LOG_DYN_LINK -o nolog -lboost_log-mt --system-header-prefix /usr/local/include -### nolog.cpp
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "-cc1" "-triple" "x86_64-apple-macosx10.13.0" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "nolog.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-fno-strict-return" "-masm-verbose" "-munwind-tables" "-target-cpu" "penryn" "-target-linker-version" "305" "-dwarf-column-info" "-debugger-tuning=lldb" "-resource-dir" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0" "--system-header-prefix=/usr/local/include" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" "-D" "BOOST_LOG_DYN_LINK" "-I/usr/local/include" "-stdlib=libc++" "-Wextra" "-fdeprecated-macro" "-fdebug-compilation-dir" "/Users/dlindelof/Work/endor/libneurobat" "-ferror-limit" "19" "-fmessage-length" "181" "-stack-protector" "1" "-fblocks" "-fobjc-runtime=macosx-10.13.0" "-fencode-extended-block-signature" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/var/folders/gf/l78h_kjs1bg6j_p18gt05_t80000gn/T/nolog-1cdc02.o" "-x" "c++" "nolog.cpp"
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" "-demangle" "-lto_library" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib" "-no_deduplicate" "-dynamic" "-arch" "x86_64" "-macosx_version_min" "10.13.0" "-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" "-o" "nolog" "-lboost_log-mt" "/var/folders/gf/l78h_kjs1bg6j_p18gt05_t80000gn/T/nolog-1cdc02.o" "-L/usr/local/lib" "-lc++" "-lSystem" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a"

UPDATE

运行xcode-select install后,问题就消失了。不知道。为什么。

c++ macos boost clang
1个回答
0
投票

正确的语法是--system-header-prefix=value。 (见https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-in-system-headers

但是,它应该像您预期的那样被视为系统头,因为默认情况下它应该具有此功能:-internal-isystem /usr/local/include

要诊断出现这种情况的原因,您需要从驱动程序发送到前端的完整命令。请添加-###以查看完整命令。

© www.soinside.com 2019 - 2024. All rights reserved.