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

            Bug ID: 103561
           Summary: internal compiler error: segmentation fault when using
                    decay copy (auto(x)) inside requires expression
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cooky.ykooc922 at gmail dot com
  Target Milestone: ---

When I attempt to use `auto(expr)` or `auto{expr}` inside `requires`
expression:

#include <concepts>
#include <utility>

template <typename T>
constexpr std::decay_t<T> decay_copy(T&& x) noexcept {
    return std::forward<T>(x);
}

void dummy() {
    int arr[] {1, 2, 1, 1};
    static_assert(requires {
        // ok:
        { arr } -> std::same_as<int(&)[4]>;
        // ok:
        { decay_copy(arr) } -> std::same_as<int*>;
        // but:
        { auto(arr) } -> std::same_as<int*>;
    });
}

The following will have an internal compiler error:
<source>: In function 'void dummy()':
<source>:17:19: internal compiler error: Segmentation fault
   17 |         { auto(arr) } -> std::same_as<int*>;
      |                   ^
0x20f3889 internal_error(char const*, ...)
        ???:0
0xa4571d template_parms_to_args(tree_node*)
        ???:0
0xa4f3c9 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int)
        ???:0
0xb3f325 build_functional_cast(unsigned int, tree_node*, tree_node*, int)
        ???:0
0xa2858d c_parse_file()
        ???:0
0xbb0f02 c_common_parse_file()
        ???:0

I'm using godbolt since GCC 12 is still experimental
(https://godbolt.org/z/M3GbGqMnb)

Reply via email to