module complie error

Bug #2039895 reported by xwj
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-11 (Ubuntu)
New
Undecided
Unassigned

Bug Description

//num.ixx

module; //global module

//#incldue <> //lib not modularized
#include <bits/stdc++.h>
export module random:num;

//import //module

// //non-export declaration

export
{
    inline int random_num(std::pair<int,int> range);
    inline int random_num(std::pair<int,int> range,int seed);

}

inline int random_num(std::pair<int, int> range)
{
    std::random_device rd; // 使用随机设备生成种子

    std::mt19937 gen(rd()); // 使用Mersenne Twister引擎

    std::uniform_int_distribution<int> dist(range.first , range.second); // 定义随机数范围

    return dist(gen);
}

inline int random_num(std::pair<int, int> range, int seed)
{
    std::mt19937 gen(seed); // 随机数引擎
    std::uniform_int_distribution<int> dist(range.first , range.second); // 定义随机数范围

    return dist(gen);
}

//random.ixx

module; //global module

//#incldue <> //lib not modularized

export module random;

//import //module
export import :num;
// //non-export declaration

export
{
    void f()
    {}

}

//complie way

MODULE_FLAGS=-g -std=c++20 -fmodules-ts -x c++ -c
 g++ ${MODULE_FLAGS} num.ixx
 g++ ${MODULE_FLAGS} random.ixx

//issue

1 . i dont know what happened since i add flag:-g
2 . before that , there still have issue :
 when i import random to use the function random_num(range) , when i step : std::random_device rd;
a error occasion from bit/string.h? but i cant formally use random_device in header system project?

Revision history for this message
xwj (xiawangjun) wrote :

++ -g -std=c++20 -fmodules-ts -x c++ -c num.ixx
g++ -g -std=c++20 -fmodules-ts -x c++ -c random.ixx
random.ixx:5:8: internal compiler error: in tree_node, at cp/module.cc:9061
    5 | export module random;
      | ^~~~~~
0x7ff64f229d8f __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x7ff64f229e3f __libc_start_main_impl
        ../csu/libc-start.c:392
Please submit a full bug report,
with preprocessed source if appropriate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.