首页 > 解决方案 > C++ - Chromium 指南样式冲突虚拟覆盖

问题描述

我正在尝试手动编译 WebRTC 库的文件。所以我正在复制一个编译行

../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF ../../../object_files/plugin.o.d -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -DCR_XCODE_VERSION=0930 -DCR_CLANG_REVISION=\"328716-2\" -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -DHAVE_PTHREAD -I../.. -Igen -I../../third_party/protobuf/src -I../../third_party -fno-strict-aliasing -fmerge-all-constants -fstack-protector-strong -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fcolor-diagnostics -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -arch x86_64 -O0 -fno-omit-frame-pointer -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -fvisibility=hidden -Xclang -load -Xclang ../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.dylib -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang no-realpath -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Werror -Wall -Wno-unused-variable -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-address-of-packed-member -Wno-unused-lambda-capture -Wno-user-defined-warnings -Wno-enum-compare-switch -Wno-null-pointer-arithmetic -Wno-ignored-pragma-optimize -Wno-unused-function -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=c++11 -stdlib=libc++ -fno-exceptions -fno-rtti -fvisibility-inlines-hidden -c ../../../source_files/plugin.cc -o ../../../object_files/plugin.o

在 protobuf 库中的plugin.cc文件上(不重要的部分被删除)

#include <google/protobuf/compiler/plugin.h>

#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>


namespace google {
namespace protobuf {
namespace compiler {

class GeneratorResponseContext : public GeneratorContext {
 public:
  GeneratorResponseContext(
      const Version& compiler_version,
      CodeGeneratorResponse* response,
      const std::vector<const FileDescriptor*>& parsed_files)
      : compiler_version_(compiler_version),
        response_(response),
        parsed_files_(parsed_files) {}
  virtual ~GeneratorResponseContext() {}

}  // namespace compiler
}  // namespace protobuf
}  // namespace google

(我知道很多)我得到了矛盾的错误

../../../source_files/plugin.cc:72:39: error: [chromium-style] Overriding method must be marked with 'override' or 'final'.
  virtual ~GeneratorResponseContext() {}
                                      ^
                                       override
../../../source_files/plugin.cc:72:3: error: [chromium-style] 'virtual' will be redundant; 'override' implies 'virtual'.
  virtual ~GeneratorResponseContext() {}
  ^~~~~~~~

我不想接触代码,因为它是由比我大得多的程序员完成的。问题似乎来自使用的定义标志。引发错误是因为该文件似乎不尊重铬指南样式。-DCLANG_REV这种铬指南样式在编译行中添加了标志。但我不知道为什么会出现这个错误,makefile 设法编译它,因为我只需要模仿 makefile 的行为,这应该也可以工作。因此,如果您有任何想法,它将对我有很大帮助,谢谢!

标签: c++clangllvm-clang

解决方案


我不想接触代码,因为它是由比我大得多的程序员完成的。

我敢肯定,如果你使用override像下面这样的特殊指令来声明析构函数,那么程序员不会生气,而是会赞美你。

~GeneratorResponseContext() override {}

或者,您可以在一行上暂时禁用 clang-tidy:

virtual ~GeneratorResponseContext() {} // NOLINT

最好的情况是按照供应商的说明独立构建protobuf库作为静态库,并在您的项目中使用静态库。


推荐阅读