为什么在运行C++ 14时会得到-wc+ 98错误?

发布于 2025-02-13 07:45:34 字数 1170 浏览 0 评论 0原文

在cmakelists.txt中,我有:

cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 14)

if(WIN32)
    set(CMAKE_CXX_FLAGS "/EHsc")
else()
    set(CMAKE_CXX_FLAGS -m64)
endif()

我验证了在Visual Studio中,实际上是在运行C ++ 14,通过执行这些步骤<< /a>

我启用了以下标志:

set(COMMON_FLAGS -Wfloat-conversion -Wsign-compare -Wsign-conversion -Wbitfield-enum-conversion -Wshorten-64-to-32 -Wstring-conversion -Werror -Wall -Wextra)

当我尝试在Visual Studio中构建时,我会遇到许多错误。通过调试,我知道它们是由-wall的抛出的:

error : 'constexpr' specifier is incompatible with C++98 [-Werror,-Wc++98-compat]
error : 'long long' is incompatible with C++98 [-Werror,-Wc++98-compat-pedantic]
error : use of this statement in a constexpr function is incompatible with C++ standards before C++14 [-Werror,-Wc++98-c++11-compat]

问题:

  1. 为什么我正在运行C ++ 14时C ++ 98错误?
  2. 为什么使用相同的cmakelists.txt在Linux运行同一项目时,这些错误 为什么会被抛弃? (在Windows上,我正在运行Clang 7.0.0,在Windows上,我正在运行Clang 5.0.1)

In CMakelists.txt, I have:

cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 14)

if(WIN32)
    set(CMAKE_CXX_FLAGS "/EHsc")
else()
    set(CMAKE_CXX_FLAGS -m64)
endif()

I verified that in visual studio, it is in fact running c++14, by doing these steps

I have the following flags enabled:

set(COMMON_FLAGS -Wfloat-conversion -Wsign-compare -Wsign-conversion -Wbitfield-enum-conversion -Wshorten-64-to-32 -Wstring-conversion -Werror -Wall -Wextra)

I get many errors like this when I try to build in visual studio. From debugging, I know that they are thrown by -Wall:

error : 'constexpr' specifier is incompatible with C++98 [-Werror,-Wc++98-compat]
error : 'long long' is incompatible with C++98 [-Werror,-Wc++98-compat-pedantic]
error : use of this statement in a constexpr function is incompatible with C++ standards before C++14 [-Werror,-Wc++98-c++11-compat]

Questions:

  1. Why are c++98 errors thrown when I am running c++14?
  2. Why do these errors not get thrown when I am running the same project in linux, using the same CMakelists.txt? (On windows I am running clang 7.0.0, and on windows I am running clang 5.0.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文