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

            Bug ID: 95175
           Summary: constexpr and alias template
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nina.didenko at gmail dot com
  Target Milestone: ---

This snippet successfully compiles using gcc6 up to gcc8.
When building using gcc 9.3.0 there is an error

template<typename R, typename... Types>
using Function = R(*)(Types...);

struct Struct
{
  void *addr;

  template<typename R, typename... Types>
  constexpr Struct(Function<R, Types...> addr) : addr((void*)(addr)) {}
};

void TestFunction()
{
}

int main(void)
{
  static constexpr Struct functions[]{
    {TestFunction},
  };
}

The error is

4.cpp: In function 'int main()':
4.cpp:20:3: error: 'constexpr Struct::Struct(Function<R, Types ...>) [with R =
void; Types = {}; Function<R, Types ...> = void (*)()]' called in a constant
expression
   20 |   };
      |   ^
4.cpp:9:13: note: 'constexpr Struct::Struct(Function<R, Types ...>) [with R =
void; Types = {}; Function<R, Types ...> = void (*)()]' is not usable as a
'constexpr' function because:
    9 |   constexpr Struct(Function<R, Types...> addr) : addr((void*)(addr)) {}

The full product code

https://github.com/TES3MP/openmw-tes3mp/blob/0.7.1/apps/openmw-mp/Script/ScriptFunctions.hpp#L120
https://github.com/TES3MP/openmw-tes3mp/blob/0.7.1/apps/openmw-mp/Script/Types.hpp#L99

Reply via email to