https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117855

            Bug ID: 117855
           Summary: Internal compiler error during substitution of
                    template with deduction guides, and causes a crash.
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anstro.pleuton at proton dot me
  Target Milestone: ---

This happens when I create a custom type that inherits std::span, and add
deduction guide to this custom type to deduce from template type Range
(std::ranges::contiguous_range), and have it auto deduce the template
parameters when constructing this custom type with a std::vector.

The test case:
```cpp
#include <cstddef>
#include <ranges>
#include <span>
#include <type_traits>
#include <vector>

template<typename element_type, std::size_t extents = std::dynamic_extent>
requires(std::is_default_constructible_v<element_type>)
struct this_span : std::span<element_type, extents> {
    using std::span<element_type, extents>::span;
};

template<std::ranges::contiguous_range Range>
this_span(Range &&) -> this_span<
    std::remove_reference_t<std::ranges::range_reference_t<Range &>>>;

int main()
{
    auto      vec = std::vector { 1, 2, 3 };
    this_span a   = vec;
}
```
Happens at `this_span a   = vec;`. Side note: Clang (clang++) only generated
one warning, an it's that `a` is unused, and generates the executable. I will
take it as unrelated issue.


The GCC output:
```
$ g++ -v -std=c++23 -Wall -Wextra -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -fsanitize=undefined -freport-bug
testcase.cpp -o testcase
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240910 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-std=c++23' '-Wall' '-Wextra' '-fno-strict-aliasing'
'-fwrapv' '-fno-aggressive-loop-optimizations' '-fsanitize=undefined'
'-freport-bug' '-o' 'testcase' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/cc1plus -quiet -v -D_GNU_SOURCE
testcase.cpp -quiet -dumpbase testcase.cpp -dumpbase-ext .cpp -mtune=generic
-march=x86-64 -Wall -Wextra -std=c++23 -version -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -fsanitize=undefined -freport-bug -o
/tmp/cctgHwT6.s
GNU C++23 (GCC) version 14.2.1 20240910 (x86_64-pc-linux-gnu)
        compiled by GNU C version 14.2.1 20240910, GMP version 6.3.0, MPFR
version 4.2.1, MPC version 1.3.1, isl version isl-0.27-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1

/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/x86_64-pc-linux-gnu

/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/backward
 /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include
 /usr/local/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include-fixed
 /usr/include
End of search list.
Compiler executable checksum: fce5a105c47978e141f61a441742cadf
In file included from /usr/include/c++/14.2.1/ranges:45,
                 from testcase.cpp:2:
/usr/include/c++/14.2.1/span: In substitution of ‘template<class _Range> 
requires  contiguous_range<_Range> std::this_span(_Range&&)->
this_span<typename remove_reference<ranges::range_reference_t<_Range&> >::type>
[with _Range = std::vector<int, std::allocator<int> >&]’:
testcase.cpp:20:21:   required from here
   20 |     this_span a   = vec;
      |                     ^~~
/usr/include/c++/14.2.1/span:466:5: internal compiler error: Segmentation fault
  466 |     span(_Range &&)
      |     ^~~~
0x21a922a internal_error(char const*, ...)
        ???:0
0x8d934f tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x8d2b6c tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x8da1ba tsubst_template_arg(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x8e2f4f tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x8cfc0e instantiate_template(tree_node*, tree_node*, int)
        ???:0
0x8eb79e fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0x73bcc9 perform_dguide_overload_resolution(tree_node*, vec<tree_node*, va_gc,
vl_embed> const*, int)
        ???:0
0x928342 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int, tree_node*)
        ???:0
0x7b7900 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???:0
0x9cd270 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues>
for instructions.
Preprocessed source stored into /tmp/ccw8EDrn.out file, please attach this to
your bugreport.
```
I have attached the generated /tmp/ccw8EDrn.out which I believe includes every
information (version, system info, command line, preprocessed file, etc.)



I did report a bug to Arch Linux at
https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues/15 .
They have confirmed that this bug is an upstream bug and I should report it to
GCC Bugzilla. I am sorry for taking a whole 2 months (I am a college student
:-( and wasn't able to give much time to these (and mostly just forgot about
it)).

Reply via email to