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

            Bug ID: 120204
           Summary: `is not usable as a 'constexpr' function because` and
                    no reason why
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

```
template<class T, int t>
struct array{};

template <typename... TArgs> struct ILEArglist {
  using Sizes = array<int, sizeof...(TArgs)>;
  static constexpr auto size() {
    Sizes &offsets_c = offsets;
    return 0;
  }
  array<char, size()> offsets();
};
auto arglist = ILEArglist<>();
```

GCC gives:
```
<source>: In instantiation of 'struct ILEArglist<>':
<source>:13:29:   required from here
   13 | auto arglist = ILEArglist<>();
      |                             ^
<source>:11:19: error: 'static constexpr auto ILEArglist<TArgs>::size() [with
TArgs = {}]' called in a constant expression
   11 |   array<char, size()> offsets();
      |               ~~~~^~
<source>:7:25: note: 'static constexpr auto ILEArglist<TArgs>::size() [with
TArgs = {}]' is not usable as a 'constexpr' function because:
    7 |   static constexpr auto size() {
      |                         ^~~~
<source>:11:19: note: in template argument for type 'int'
   11 |   array<char, size()> offsets();
      |               ~~~~^~
Compiler returned: 1
```

While clang gives:
```

<source>:8:24: error: call to non-static member function without an object
argument
    8 |     Sizes &offsets_c = offsets;
      |                        ^~~~~~~
<source>:8:12: error: declaration of reference variable 'offsets_c' requires an
initializer
    8 |     Sizes &offsets_c = offsets;
      |            ^~~~~~~~~
<source>:11:15: note: in instantiation of member function 'ILEArglist<>::size'
requested here
   11 |   array<char, size()> offsets();
      |               ^
<source>:13:16: note: in instantiation of template class 'ILEArglist<>'
requested here
   13 | auto arglist = ILEArglist<>();
      |                ^
```

Reply via email to