如何构建包含C 11的恒定表达式的代码

How to build code that contains constant expression with c++11

本文关键字:代码 表达式 包含 何构建 构建      更新时间:2023-10-16

你好,我正在测试新的C 库:Martchus的Tagparserhttps://github.com/martchus/tagparser编译以下代码时,我会遇到错误:

代码:

#include <tagparser/mediafileinfo.h>
#include <tagparser/diagnostics.h>
using namespace TagParser;
// create a MediaFileInfo for high-level access to overall functionality of the library
MediaFileInfo fileInfo;
// create container for errors, warnings, etc.
Diagnostics diag;
...

错误:

In file included from /usr/include/c++/5/cstdint:35:0,
                 from /usr/local/include/c++utilities/conversion/types.h:4,
                 from /usr/local/include/tagparser/tagtarget.h:6,
                 from /usr/local/include/tagparser/settings.h:4,
                 from /usr/local/include/tagparser/abstractcontainer.h:5,
                 from /usr/local/include/tagparser/mediafileinfo.h:4,
                 from TagParserTest.cpp:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error:
#error This file requires compiler and library support for the ISO C++ 2011 standard.
This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

当我尝试使用-std=c++11选项构建时,我会得到此错误:

In file included from /usr/local/include/tagparser/abstractcontainer.h:5:0,
                 from /usr/local/include/tagparser/mediafileinfo.h:4,
                 from TagParserTest.cpp:1:
/usr/local/include/tagparser/settings.h: In function ‘constexpr TagParser::TagCreationFlags& TagParser::operator|=(TagParser::TagCreationFlags&, TagParser::TagCreationFlags)’:
/usr/local/include/tagparser/settings.h:53:1: error: expression ‘(lhs = ((TagParser::TagCreationFlags)(((std::underlying_type<TagParser::TagCreationFlags>::type)lhs) | ((std::underlying_type<TagParser::TagCreationFlags>::type)rhs))))’ is not a constant-expression
 }

我真的不知道该如何解决。谁能帮我?

非常感谢丹尼尔·H。当我使用C 14代替C 11时,它可以正常工作。

谢谢。