Skip to content

Incorrect code generated for final template specialisations #391

@TerensTare

Description

@TerensTare

Sample code: https://cppinsights.io/s/84d98d4f

Consider the specialisation tnt::serializer<my_type> instantiated. It generates the following code:

   /* First instantiated from: insights.cpp:98 */
  #ifdef INSIGHTS_USE_TEMPLATE
  template<>
  struct serializer final<my_type> // notice the type after `final`
  {
    template<typename Vis>
    static inline constexpr void get_visit(Vis && vis);
    
    /* First instantiated from: insights.cpp:98 */
    #ifdef INSIGHTS_USE_TEMPLATE
    template<>
    static inline constexpr void get_visit<printer<my_type> &>(printer<my_type> & vis)
    {
      wrap.operator()(std::forward<printer<my_type> &>(vis));
    }
    #endif
    
    inline static constexpr const wrapper<my_type> wrap = wrapper<my_type>();
  };
  
  #endif

The same applies to user-defined specialisations like tnt::wrapper<my_type> from the same code

template<>
struct tnt::wrapper final<my_type> // notice the type after `final`
{
template<typename Vis>
inline constexpr void operator()(Vis && vis) const
{
  vis("a", &my_type::a);
  vis("b", &my_type::b);
}

/* First instantiated from: insights.cpp:68 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline constexpr void operator()<tnt::printer<my_type> &>(tnt::printer<my_type> & vis) const
{
  vis.operator()(std::basic_string_view<char, std::char_traits<char> >("a"), &my_type::a);
  vis.operator()(std::basic_string_view<char, std::char_traits<char> >("b"), &my_type::b);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions