Bug 115257 - Error when compiling a program with module and println and auto
Summary: Error when compiling a program with module and println and auto
Status: RESOLVED DUPLICATE of bug 114275
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: c++-modules
  Show dependency tree / graph
 
Reported: 2024-05-28 10:47 UTC by Koki Fushimi
Modified: 2024-06-01 02:10 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Koki Fushimi 2024-05-28 10:47:07 UTC
When I tried to make a following program with module and <print> and autos, failed to compile.

$ g++-14 -std=c++23 -fmodules-ts -x c++-system-header print
$ g++-14 -std=c++23 -fmodules-ts -Wall -Wextra -save-temps hello.cpp main.cpp -o main
In file included from /usr/local/Cellar/gcc/14.1.0/include/c++/14/print:41,
of module /usr/local/Cellar/gcc/14.1.0/include/c++/14/print, imported at hello.cpp:3,
of module hello, imported at main.cpp:1:
/usr/local/Cellar/gcc/14.1.0/include/c++/14/format: In instantiation of 'struct std::__format::_Runtime_format_string<char>':
/usr/local/Cellar/gcc/14.1.0/include/c++/14/print:129:19:   required from 'void std::println(format_string<_Args ...>, _Args&& ...) [with _Args = {const char (&)[4]}; format_string<_Args ...> = basic_format_string<char, const char (&)[4]>]'
  129 |     { std::println(stdout, __fmt, std::forward<_Args>(__args)...); }
      |       ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello.cpp:7:21:   required from 'auto hello::greeting@hello(const auto:1&) [with auto:1 = char [4]]'
    7 |         std::println("Hello, {}!", x);
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
main.cpp:4:20:   required from here
    4 |     hello::greeting("C++");
      |     ~~~~~~~~~~~~~~~^~~~~~~
/usr/local/Cellar/gcc/14.1.0/include/c++/14/format:74:55: internal compiler error: Segmentation fault: 11
   74 |   template<typename _CharT, typename... _Args> struct basic_format_string;
      |                                                       ^~~~~~~~~~~~~~~~~~~
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <https://github.com/Homebrew/homebrew-core/issues> for instructions.
$ cat main-hello.ii
# 0 "hello.cpp"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "hello.cpp"
export  module  hello;

import  "/usr/local/Cellar/gcc/14.1.0/include/c++/14/print";

export namespace hello {
    auto greeting(auto const & x) {
        std::println("Hello, {}!", x);
    }
}
$ cat main-main.ii
# 0 "main.cpp"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "main.cpp"
import  hello;

int main() {
    hello::greeting("C++");
}

If I don't use module, but use `#include` then it works, and
if I don't use std::println of <print> and use std::cout of <iostream>, then it works, and
if I don't use autos, and specify the types `void` and `char const *`, then it works.

I'm using macOS Ventura 13.6.7, and GCC 14.1.0.
$ g++-14 --version
g++-14 (Homebrew GCC 14.1.0) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Nathaniel Shead 2024-06-01 02:10:09 UTC
Looks to be the same issue as PR114275, fixed on trunk.

*** This bug has been marked as a duplicate of bug 114275 ***