C++20: source_location::current() doesn't work inside Modules?

Viewed 353

I have an .ixx module on Visual Studio (MSVC) called Test that exports a simple struct:

export module Test;
import std.core;

export struct Test {
    Test(std::source_location src = std::source_location::current()) {
        info.append(src.function_name());
    }
    std::string info;
};

Then, on main.cpp i import the Module and call the constructor:

import std.core;
import Test;

int main() {
    std::cout << Test().info;
}

It won't compile, giving the following error:

Error C7595 'std::source_location::current': call to immediate function is not a constant expression

However, if you try to do the exact same thing but outside of a module (all in main.cpp or a separate .cpp/header class) it compiles and works just fine:

import std.core;

struct Test {
    Test(std::source_location src = std::source_location::current()) {
        info.append(src.function_name());
    }
    std::string info;
};


int main() {
    std::cout << Test().info;
}

As a side note, the first module example works perfectly fine in GCC and does not give any error or warning (of course you can't import std.core, you just #include the required headers instead) even though modules are not fully implemented in GCC, while they are in MSVC. Does anyone know what's going on here? Maybe there's something i'm missing?

0 Answers
Related