Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOOST_LOG_TRIVIAL and C++20 modules #112

Closed
Patschkowski opened this issue Sep 7, 2023 · 3 comments
Closed

BOOST_LOG_TRIVIAL and C++20 modules #112

Patschkowski opened this issue Sep 7, 2023 · 3 comments

Comments

@Patschkowski
Copy link

Dear all,

I am facing the following challenge when using the BOOST_LOG_TRIVIAL functionality from C++20 modules.

// foo.ixx
module;

#include <boost/log/trivial.hpp>

export module foo;

export namespace foo {

template<typename T>
void bar()
{
    BOOST_LOG_TRIVIAL(info) << "Hello, World!";
}

}
// main.cpp
#include <compare>

import foo;

int main()
{
    foo::bar<int>();
    return 0;
}

This code fails to compile on my Visual Studio 2022 with the following error message.

boost\log\keywords\severity.hpp(32,1): error C7631: 'boost::log::v2_mt_nt6::keywords::`anonymous-namespace'::severity': variable with internal linkage declared but not defined

My current understanding of this issue is that, based on Understanding C++ Modules: Part 3: Linkage and Fragments, severity has module internal linkage because it is in an anonymous namespace. But as bar is a template, it must also be available to importers that instantiate the template, which is not allowed. So the code fails to compile.

Is there any way around this or can the library be improved to also support this scenario?

Thanks in advance,
Felix

@Lastique Lastique transferred this issue from boostorg/log Sep 7, 2023
@Lastique
Copy link
Member

Lastique commented Sep 7, 2023

  1. Boost.Log uses Boost.Parameter to define its parameter keywords. Since the problem is with a parameter keyword definition, I moved the issue there.
  2. The error message doesn't make sense. You can see how the keyword is defined here, and that is a variable definition, given that there is an initializer. I think this is a compiler bug and should be reported to Microsoft.
  3. I don't have experience with modules, but I'm pretty sure exported functions must be able to use symbols from anonymous namespaces in their body. What symbols the function body uses has no effect on the function's linkage, otherwise you wouldn't be able to use objects and functions with internal linkage at all. So I'm sure the anonymous namespace is not a problem, not wrt. symbol linkage.
  4. Unfortunately, I don't have a workaround for you, other than to not use modules or try a different compiler.

@Lastique Lastique closed this as completed Sep 7, 2023
@Patschkowski
Copy link
Author

I think this should be reconsidered based on the Microsoft feedback given here: https://developercommunity.visualstudio.com/t/error-C7631:-when-instantiating-template/10476144

But also it links to this issue: #111

@Lastique
Copy link
Member

I do not agree with their feedback, I left a comment there. And if it is indeed the intended behavior that is mandated by the C++ standard then I consider modules specification broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants