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

Compilation with -fmodules-ts and use inside of a module #3472

Closed
2 tasks
ghost opened this issue May 7, 2022 · 4 comments
Closed
2 tasks

Compilation with -fmodules-ts and use inside of a module #3472

ghost opened this issue May 7, 2022 · 4 comments
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@ghost
Copy link

ghost commented May 7, 2022

Description

Hi,
When just including #include <nlohmann/json.hpp> in a module, the compiler complains about impossible references.
It is not happening when not inside a module.

Reproduction steps

Just include the header inside a module and compile with -fmodules-ts.

This is the triggering flag, really.

Expected vs. actual results

No error

Minimal code example

//mod.cxx:

module;
#include <iostream>
#include <string_view>
#include <string>
#include <nlohmann/json.hpp>
export module hello;

export {
        namespace X {

                void greeter ( std::string_view const &name ){
                        std::string h = "exported greeter";

                        std::cout << "Hello " << name << "!" << h << "\n";

                }

        }
}


// main.cpp
import hello;

int main ( void ){

        X::greeter("ok");
        return 0;
}

// compile with
~/gcc-12.1/g++ -fmodules-ts -std=c++20 -I/my_path/include/ mod.cxx main.cpp

Error messages

`/usr/include/nlohmann/adl_serializer.hpp:41:17: error: ‘static decltype ((nlohmann::{anonymous}::to_json(j, forward<ValueType>(val)), void())) nlohmann::adl_serializer<T, SFINAE>::to_json(BasicJsonType&, ValueType&&) [with BasicJsonType = nlohmann::basic_json<>; ValueType = bool&; <template-parameter-1-1> = bool; <template-parameter-1-2> = void; decltype ((nlohmann::{anonymous}::to_json(j, forward<ValueType>(val)), void())) = void]’ references internal linkage entity ‘constexpr const nlohmann::detail::to_json_fn& nlohmann::{anonymous}::to_json’
   41 |     static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(`

Compiler and operating system

Linux GCC-12.1

Library version

Latest

Validation

@ghost ghost added the kind: bug label May 7, 2022
@falbrechtskirchinger
Copy link
Contributor

If the issue is what I suspect it is, this should be easily fixable. I'll take a look.

@falbrechtskirchinger
Copy link
Contributor

I was able to fix the linkage issues by marking the relevant entities inline but your code then results in an ICE:

 $ g++-13.0.0 -fmodules-ts -std=c++20 -I../fix-c++20-issues-part2/include/ mod.cxx main.cpp
main.cpp: In function ‘int main()’:
main.cpp:4:12: internal compiler error: Segmentation fault
    4 |         X::greeter("ok");
      |            ^~~~~~~
0x7fcf08bf793f ???
        /var/tmp/portage/sys-libs/glibc-2.35-r4/work/glibc-2.35/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7fcf08be3389 __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x7fcf08be343b __libc_start_main_impl
        ../csu/libc-start.c:392
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.

(And GCC 12 crashes as well.)

You can grab the fixed code from my modules branch. Maybe you can figure out why GCC is crashing.

https://github.com/falbrechtskirchinger/json/tree/modules

(The code is running through CI right now. If there're any problems I will update this post.)

@ghost
Copy link
Author

ghost commented May 7, 2022

Thanks!
There is a much deeper issue in the handling of modules in gcc and I reported a bug this morning.

I will try your fix once I get some lights 👍👍

@falbrechtskirchinger
Copy link
Contributor

@nlohmann This bug can be closed. Fixed by #3446 (4f744f4).

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation release item: 🐛 bug fix labels Jul 30, 2022
@nlohmann nlohmann self-assigned this Jul 30, 2022
@nlohmann nlohmann added this to the Release 3.11.0 milestone Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants