Problem compiling SMTK with C++ 17 using Visual Studio 22
The compiler crashes when processing smtk/plugin/Client.xx.
SMTK : smtk/plugin/Client.xx
#ifndef smtk_plugin_Client_txx
#define smtk_plugin_Client_txx
#include "smtk/plugin/Client.h"
#include "smtk/plugin/ClientBase.h"
#include "smtk/plugin/Manager.h"
namespace smtk
{
namespace plugin
{
template<typename Registrar_t, typename Manager_t, typename... T>
std::shared_ptr<ClientBase> Client<Registrar_t, Manager_t, T...>::create()
{
std::shared_ptr<Client<Registrar_t, Manager_t, T...>> shared(
new Client<Registrar_t, Manager_t, T...>);
smtk::plugin::Manager::instance()->addClient(
std::static_pointer_cast<ClientBase>(shared->ClientBase::shared_from_this())); <-----
return std::static_pointer_cast<ClientBase>(shared);
}
} // namespace plugin
} // namespace smtk
#endif
The indicated line is where the compiler crashed.
If the file CMake/smtkPluginInitializer.cxx.in is changed to this:
namespace smtk
{
namespace plugin
{
template<>
std::shared_ptr<ClientBase>
Client<
@_smtk_plugin_REGISTRAR@,
@_smtk_plugin_managers@
>::create()
{
std::shared_ptr<
Client<@_smtk_plugin_REGISTRAR@,
@_smtk_plugin_managers@>>
shared(new Client<@_smtk_plugin_REGISTRAR@,
@_smtk_plugin_managers@>);
smtk::plugin::Manager::instance()->addClient(
std::static_pointer_cast<ClientBase>(shared->ClientBase::shared_from_this()));
return std::static_pointer_cast<ClientBase>(shared);
}
} // namespace plugin
} // namespace smtk
namespace smtk
{
namespace plugin
{
namespace init
{
using Client = smtk::plugin::Client<
@_smtk_plugin_REGISTRAR@,
@_smtk_plugin_managers@
>;
static std::shared_ptr<Client> myClient;
void @_smtk_plugin_autostart_name@()
{
myClient = std::dynamic_pointer_cast<Client>(Client::create());
}
}
}
}
Which includes a manual installation of the template for ClientBase - the code will compiler.
The question is "Is this ok to put in as a workaround for Visual Studio?" Assuming it is properly ifdef'd.
Edited by Robert M. O'Bara