4
#define _GLIBCXX_CONCEPT_CHECKS
#include <regex>
void f() { std::regex r("hello"); }

When the above is compiled as C++11 in either GCC or Clang, an enormous template error is generated, the key part of which seems to be:

/opt/gcc-5.3.0/include/c++/5.3.0/bits/boost_concept_check.h:206:11: error: use of deleted function 'std::__detail::_StateSeq >& std::__detail::_StateSeq >::operator=(const std::__detail::_StateSeq >&)'
__a = __a; // require assignment operator
^

But taking a guess at what that means, I notice that std::regex does have an assignment operator.

Also, it is my understanding that enabling concepts ought not to change whether the code compiles. However, removing the #define makes it compile.


Two part question:

  1. Is this error, and its appearance only when concepts are enabled, correct behavior?
  2. If yes, how am I supposed to make a regex?
2
  • Just guessing, try using a std::string in the constructor rather than a string constant. Commented Aug 23, 2016 at 3:10
  • gcc 6.1 doesn't give any error, seems a bug of old gcc Commented Aug 23, 2016 at 3:46

2 Answers 2

4

Change your code to the following:

#include <regex>
#define _GLIBCXX_CONCEPT_CHECKS
void f() { std::regex r("hello"); }

This will disable concept checks for the regex library code, but will leave the concept checks enabled for whatever else you want to do in this compilation unit. Basically the version of the regex library that you have is not compatible with the concept checks that your compiler version checks for. This error is seen in versions 5.3 or lower of GCC that use C++ 11 but not seen in versions 6.1 or higher that also use C++ 11.

Sign up to request clarification or add additional context in comments.

Comments

0

With my GCC 5.4 project, I have to put <regex> first in my includes when concept checks are on for the whole project (as set in the makefile) because apparently there is some indirect way that it it interacts with other headers, none of which included regex directly themselves AFAICT.

#ifdef _GLIBCXX_CONCEPT_CHECKS
#undef _GLIBCXX_CONCEPT_CHECKS // GCC 5 library bug requires that we disable this for regex 
#define NEED_REDEF_OF_GLIBCXX_CONCEPT_CHECKS
#endif
// Standard headers
#include <regex>
#ifdef NEED_REDEF_OF_GLIBCXX_CONCEPT_CHECKS
#define _GLIBCXX_CONCEPT_CHECKS
#endif
// Other headers here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.