2

I have the following code:

#include "type_traits"

template<typename T_>
struct thing{
    template<typename me_type>
    struct inner { 
        static T_& impl_0 (void* me ) { return static_cast<me_type*>(me )->operator*(); } 

        static auto getThing()
        {
            return std::integral_constant<T_& (*)(void*),&impl_0>();
        }
    };
};

It declares a static function inside a templated class that is inside another templated class.

Then it declares an auto function, which returns an pointer to that function, but first it puts it into a std::integral_constant

When I give this to gcc version 7.3 (godbolt) with the compiler flags -std=c++14 it complains:

<source>: In static member function 'static auto thing<T_>::inner<me_type>::getThing()':
<source>:11:69: error: template argument 2 is invalid
                 return std::integral_constant<T_& (*)(void*),&impl_0>();

But when I give it to clang version 6.0.0 it compiles just fine (godbolt).

Should it compile or not?

DarthRubik
  • 3,927
  • 1
  • 18
  • 54

1 Answers1

1

I think, it should compile as is, because function name should be visible. However, that fixes it:

    struct inner { 
        static auto getThing()
        {
            return std::integral_constant<T_& (*)(void*),&inner::impl_0>();
        }
    };
SergeyA
  • 61,605
  • 5
  • 78
  • 137