llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Frontend segfault on a trailing return type containing a constant-wrapper template (C++20)

Open ICSE-27 opened this issue 2 months ago • 1 comments

Environment

Clang 19.1.0 (x86-64-unknown-linux-gnu, release build without assertions)

Command

$ clang++ -std=c++20 -pedantic-errors -c test8.cpp

Actual behavior

Segmentation fault: return-type deduction (DeduceAutoType) dereferences a null type pointer while instantiating the constant wrapper in the trailing return type.

Additional notes

The test case was produced by an automated compiler-testing tool (GapSmith).

Test case (test8.cpp)

template <auto V>
struct ConstantWrapper {
  static constexpr auto value = V;

  template <class... Ts>
  constexpr auto operator()(Ts... args) const -> ConstantWrapper<value(Ts::value...)> {
    return {};
  }
};

struct Plus {
  template <class T, class U>
  constexpr auto operator()(T&& t, U&& u) const -> decltype(static_cast<T&&>(t) + static_cast<U&&>(u)) {
    return static_cast<T&&>(t) + static_cast<U&&>(u);
  }
};

constexpr auto cwv = ConstantWrapper<Plus{}>{}(ConstantWrapper<42>{}, ConstantWrapper<17>{});

ICSE-27 avatar Sep 26 '26 12:09 ICSE-27

@llvm/issue-subscribers-clang-frontend

Author: ICSE-27

## Environment Clang 19.1.0 (x86-64-unknown-linux-gnu, release build without assertions)

Command

clang++ -std=c++20 -pedantic-errors -c test8.cpp

Actual behavior

Segmentation fault: return-type deduction (DeduceAutoType) dereferences a null type pointer while instantiating the constant wrapper in the trailing return type.

Additional notes

The test case was produced by an automated compiler-testing tool (GapSmith).

Test case (test8.cpp)

template &lt;auto V&gt;
struct ConstantWrapper {
  static constexpr auto value = V;

  template &lt;class... Ts&gt;
  constexpr auto operator()(Ts... args) const -&gt; ConstantWrapper&lt;value(Ts::value...)&gt; {
    return {};
  }
};

struct Plus {
  template &lt;class T, class U&gt;
  constexpr auto operator()(T&amp;&amp; t, U&amp;&amp; u) const -&gt; decltype(static_cast&lt;T&amp;&amp;&gt;(t) + static_cast&lt;U&amp;&amp;&gt;(u)) {
    return static_cast&lt;T&amp;&amp;&gt;(t) + static_cast&lt;U&amp;&amp;&gt;(u);
  }
};

constexpr auto cwv = ConstantWrapper&lt;Plus{}&gt;{}(ConstantWrapper&lt;42&gt;{}, ConstantWrapper&lt;17&gt;{});