简体   繁体   English

GCC:使用c ++ 11时发出警告

[英]GCC: emit warnings when c++11 is used

Given 特定

Cross-platform C++ project that has to build on some ancient windows mobile platforms. 必须在某些古老的Windows移动平台上构建的跨平台C ++项目。 However the development is done with GCC. 但是,开发工作已由GCC完成。

Problem 问题

Every time that C++11 feature is used it will build locally but fail on the build server (mobile windows). 每次使用C ++ 11功能时,它将在本地生成,但在生成服务器(移动Windows)上将失败。

Question

Is it possible to configure GCC to somehow warn if C++11 feature is used in our code-base (excluding other source-dependencies). 如果在我们的代码库中使用了C ++ 11功能,是否可以将GCC配置为以某种方式发出警告(不包括其他源依赖项)。

What have you tried? 你尝试了什么?

I know about using -std=c++98 -pedantic , but: 我知道使用-std=c++98 -pedantic ,但是:

  1. I would like to use the latest compiler standard on Linux platform 我想在Linux平台上使用最新的编译器标准
  2. There are some linux-only third-party dependencies (build from the source) that require C++11 有一些仅Linux的第三方依赖项(从源构建)需要C ++ 11

Build the code you need to be C++98 compatible using C++98 flags. 使用C ++ 98标志构建需要与C ++ 98兼容的代码。

Build the code you need to be C++11 compatible using C++11 flags. 使用C ++ 11标志构建需要与C ++ 11兼容的代码。

Examine the documentation of the compiler and standard library used to ensure ABI compatibility between code built with C++98 and C++11; 检查用于确保使用C ++ 98和C ++ 11构建的代码之间的ABI兼容性的编译器和标准库的文档; you may have to (for example) use C++98 strings in your C++11 code in order to have ABI compatibility, assuming you pass std::string s between the C++98 and C++11 code bases. 为了具有ABI兼容性,可能需要(例如)在C ++ 11代码中使用C ++ 98字符串,前提是您在C ++ 98和C ++ 11代码库之间传递了std::string

You cannot both use C++11 and not use C++11 when building the same file, unless you build it twice. 除非生成两次,否则在构建同一文件时不能同时使用C ++ 11和不使用C ++ 11。 Which is also an option; 这也是一种选择; build the C++98 compatible stuff twice, once with C++latest and once with C++98. 两次构建C ++ 98兼容的东西,一次使用C ++ latest,一次使用C ++ 98。 Throw away the C++98 build after halting on errors and warnings. 停止错误和警告后,放弃C ++ 98构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM