5

I came across a strange problem. I made a C++20 module with the following content (file module.cppm):

module;
#include <regex>
#include <string>

export module foo;

export namespace bar {
    using std::regex;
    using std::smatch;
    using std::regex_search;
    using std::string;
}

I use this module in the following code (file main.cpp):

import foo;

int main() {
    bar::regex  regex;
    bar::smatch match;
    bar::string s;
    bar::regex_search(s, match, regex);
}

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 4.0.0)
set(CMAKE_CXX_STANDARD 23)

project(cpptest)

add_library(module STATIC)
target_sources(module PUBLIC FILE_SET CXX_MODULES FILES module.cppm)

add_executable(cpptest main.cpp)
target_link_libraries(cpptest module)

When trying to build with the following commands:

cmake -B build -G Ninja
cmake --build ./build/

I get the following errors:

/usr/local/gcc-15.1/include/c++/15/bits/regex.tcc:56:16: error: ‘std::__cxx11::basic_regex<char>::_AutomatonPtr std::__cxx11::basic_regex<char>::_M_automaton’ is private within this context
56 | if (__re._M_automaton == nullptr)
| ~~~~~^~~~~~~~~~~~
/usr/local/gcc-15.1/include/c++/15/bits/regex.h:848:25: note: declared private here
848 | _AutomatonPtr _M_automaton;

My compiler is GCC 15.1, cmake 4.0.3. Here is a reproduction of this example on godbolt. If you compile the same example in Clang, there is no problem.

Is there a quick fix for this? Is GCC aware of this issue?

1
  • 1
    It's most likely a bug. Commented Sep 5 at 13:07

1 Answer 1

0

The new version of gcc-16 (trunk) fixed this issue. The original example now works (though you need to export the new operator for this to work).

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

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.