Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect code generated for final template specialisations #391

Closed
TerensTare opened this issue Mar 27, 2021 · 1 comment
Closed

Incorrect code generated for final template specialisations #391

TerensTare opened this issue Mar 27, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@TerensTare
Copy link

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);
}
@andreasfertig
Copy link
Owner

Hello @TerensTare,

thanks for spotting this! I probably introduced it recently by adding support for final in the first place. Your example revealed another issue, member-pointers are not transformed correctly. A fix for both is on its way.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label Mar 27, 2021
andreasfertig added a commit that referenced this issue Mar 27, 2021
Fixed #391: Placement of `final` was wrong for a class template.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants