Ошибка при попытке скомпилировать учебник по регулярному выражению c ++ 11 с помощью Clang ++ в Linux

Я пытаюсь следовать этот урок о регулярных выражениях в C ++ 11. Когда я пытаюсь скомпилировать небольшой пример кода, я получаю эти ошибки

clang++ -std=c++0x test.cpp -o test
In file included from test.cpp:3:
In file included from /usr/include/c++/4.6/regex:55:
/usr/include/c++/4.6/bits/regex_constants.h:196:36: error: constexpr variable
'match_default' must be initialized by a constant expression
static constexpr match_flag_type match_default     = 0;
^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:203:36: error: constexpr variable
'match_not_bol' must be initialized by a constant expression
static constexpr match_flag_type match_not_bol     = 1 << _S_not_bol;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:210:36: error: constexpr variable
'match_not_eol' must be initialized by a constant expression
static constexpr match_flag_type match_not_eol     = 1 << _S_not_eol;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:216:36: error: constexpr variable
'match_not_bow' must be initialized by a constant expression
static constexpr match_flag_type match_not_bow     = 1 << _S_not_bow;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:222:36: error: constexpr variable
'match_not_eow' must be initialized by a constant expression
static constexpr match_flag_type match_not_eow     = 1 << _S_not_eow;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:228:36: error: constexpr variable
'match_any' must be initialized by a constant expression
static constexpr match_flag_type match_any         = 1 << _S_any;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:233:36: error: constexpr variable
'match_not_null' must be initialized by a constant expression
static constexpr match_flag_type match_not_null    = 1 << _S_not_null;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:238:36: error: constexpr variable
'match_continuous' must be initialized by a constant expression
static constexpr match_flag_type match_continuous  = 1 << _S_continuous;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:245:36: error: constexpr variable
'match_prev_avail' must be initialized by a constant expression
static constexpr match_flag_type match_prev_avail  = 1 << _S_prev_avail;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:273:36: error: constexpr variable
'format_default' must be initialized by a constant expression
static constexpr match_flag_type format_default    = 0;
^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:281:36: error: constexpr variable
'format_sed' must be initialized by a constant expression
static constexpr match_flag_type format_sed        = 1 << _S_sed;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:288:36: error: constexpr variable
'format_no_copy' must be initialized by a constant expression
static constexpr match_flag_type format_no_copy    = 1 << _S_no_copy;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.6/bits/regex_constants.h:294:36: error: constexpr variable
'format_first_only' must be initialized by a constant expression
static constexpr match_flag_type format_first_only = 1 << _S_first_only;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 errors generated.

В чем дело?

3

Решение

По умолчанию clang использует стандартную библиотеку C ++ от gcc — libstdc ++. Он по-прежнему не поддерживает регулярные выражения. Вы можете попробовать использовать libc ++ — еще одну реализацию стандартной библиотеки, которая поддерживает все C ++ 11. clang++ -stdlib=libc++ source.cpp -o source отлично работает для меня с первым примером кода из учебника.

Однако не стоит объединять библиотеки / исполняемые файлы libc ++ и libstdc ++ — они несовместимы.

0

Другие решения

Других решений пока нет …