[Bug c++/97749] New: ICE: Segmentation Fault on C++20 NTTP

janpmoeller at gmx dot de gcc-bugzilla@gcc.gnu.org
Fri Nov 6 23:46:14 GMT 2020


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

            Bug ID: 97749
           Summary: ICE: Segmentation Fault on C++20 NTTP
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janpmoeller at gmx dot de
  Target Milestone: ---

The following code results in an ICE when compiled with gcc-10.2 or the latest
trunk:

/////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <string_view>

template<std::size_t N>
struct fixed_string
{
    char buf[N + 1]{};
    constexpr fixed_string(char const* s) { std::copy_n(s, N, buf); }
    constexpr operator char const *() const { return buf; }
    constexpr operator std::string_view() const { return buf; }
};
template<std::size_t N>
fixed_string(char const (&)[N]) -> fixed_string<N - 1>;

template<fixed_string Literal>
struct foo;

template<typename T>
struct bar;

template<fixed_string Literal>
struct bar<foo<Literal.buf>>
{};

int main()
{
    bar<foo<"foobar">> foobar;
}
/////////////////////////////////////////////////////////////////////////////

This is the output:

#############################################################################
<source>:22:24: internal compiler error: Segmentation fault
   22 | struct bar<foo<Literal.buf>>
      |                        ^~~
0x1be3959 internal_error(char const*, ...)
        ???:0
0x6ad485 resolve_args(vec<tree_node*, va_gc, vl_embed>*, int)
        ???:0
0x89f9af do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int)
        ???:0
0x8bf5ac lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
        ???:0
0x91439d finish_template_type(tree_node*, tree_node*, int)
        ???:0
0x87a2ac c_parse_file()
        ???:0
0x9f0f52 c_common_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
ASM generation compiler returned: 1
#############################################################################

gcc was invoked with "-std=c++20 -Wall -Wextra -Wpedantic". The error can also
be observed on compiler explorer: https://godbolt.org/z/7abb75

I believe that this is valid C++20 and should compile.


More information about the Gcc-bugs mailing list