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

MSVC bug on template function specialization with default argument #487

Closed
jslee02 opened this issue Aug 13, 2015 · 3 comments
Closed

MSVC bug on template function specialization with default argument #487

jslee02 opened this issue Aug 13, 2015 · 3 comments
Milestone

Comments

@jslee02
Copy link
Member

jslee02 commented Aug 13, 2015

I observed that Visual Studio 2013 complains for template function specialization with default argument. This happens in the following code of DART for instance:

  template <class JointType, class NodeType = BodyNode>
  std::pair<JointType*, NodeType*> createJointAndBodyNodePair(
    BodyNode* _parent = nullptr,
      const typename JointType::Properties& _jointProperties
          = typename JointType::Properties(),  // syntax error C2689 and C2059
      const typename NodeType::Properties& _bodyProperties
          = typename NodeType::Properties());  // syntax error C2689 and C2059

There are reports on this issue: stackoverflow1, stackoverflow2 and upstream bug report. From the reports, possible workaround is to wrap the calls as:

#ifdef _WIN32
  template <typename JointType>
  static typename JointType::Properties createJointProperties()
  {
    return typename JointType::Properties();
  }

  template <typename NodeType>
  static typename NodeType::Properties createBodyNodeProperties()
  {
    return typename NodeType::Properties();
  }
#endif

  template <class JointType, class NodeType = BodyNode>
  std::pair<JointType*, NodeType*> createJointAndBodyNodePair(
    BodyNode* _parent = nullptr,
#ifdef _WIN32
      const typename JointType::Properties& _jointProperties
          = Skeleton::createJointProperties<JointType>(),  // ok
      const typename NodeType::Properties& _bodyProperties
          = Skeleton::createBodyNodeProperties<NodeType>());  // ok
#else
      const typename JointType::Properties& _jointProperties
          = typename JointType::Properties(),
      const typename NodeType::Properties& _bodyProperties
          = typename NodeType::Properties());
#endif

It seems VS2010, VS2012, and VS2013 are all have this bug but I haven't tested with VS2015.

@jslee02
Copy link
Member Author

jslee02 commented Aug 29, 2015

Fixed by #486.

@jslee02 jslee02 closed this as completed Aug 29, 2015
@jslee02
Copy link
Member Author

jslee02 commented Apr 22, 2016

I reopen this issue to see if this works with VS2015 now once #599 is resolved.

@jslee02 jslee02 reopened this Apr 22, 2016
@jslee02
Copy link
Member Author

jslee02 commented Jan 12, 2018

Confirmed this patch works by #956

@jslee02 jslee02 closed this as completed Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant