grasph/wrapit

Generates wrappers for deleted methods and constructors

Closed this issue · 4 comments

Given following class declaration in Geant4 (QBBC.hh)

class QBBC : public G4VModularPhysicsList
{
public:
  explicit QBBC(G4int ver = 1, const G4String& type = "QBBC");
  virtual ~QBBC()=default;
  // copy constructor and hide assignment operator
  QBBC(const QBBC &)=delete;
  QBBC & operator=(const QBBC &right)=delete;
};

generates wrappers for deleted methods

 DEBUG_MSG("Adding wrapper for void QBBC::QBBC(G4int, const G4String &) (" __HERE__ ")");
  // defined in /Users/mato/Development/views/dev4/x86_64-mac11-clang120-opt/include/Geant4/QBBC.hh:47:12
  t7.constructor<>();
  t7.constructor<G4int>();
  t7.constructor<G4int, const G4String &>();

  DEBUG_MSG("Adding wrapper for void QBBC::QBBC(const QBBC &) (" __HERE__ ")");
  // defined in /Users/mato/Development/views/dev4/x86_64-mac11-clang120-opt/include/Geant4/QBBC.hh:52:3
  t7.constructor<const QBBC &>();

  DEBUG_MSG("Adding wrapper for QBBC & QBBC::operator=(const QBBC &) (" __HERE__ ")");
  // signature to use in the veto list: QBBC & QBBC::operator=(const QBBC &)
  // defined in /Users/mato/Development/views/dev4/x86_64-mac11-clang120-opt/include/Geant4/QBBC.hh:53:10
  t7.method("assign", static_cast<QBBC & (QBBC::*)(const QBBC &) >(&QBBC::operator=));

which fails to compile with error: call to deleted constructor of 'QBBC'

Hello @peremato,

I expect it is fixed by your PR, which has been merged.

Please reopen the issue if the PR does not completely fix it.

Philippe.

I am getting now, more problems of this sort when using the current master branch.

In file included from /Users/mato/Development/Julia/Geant4.jl/gen/cpp/jlGeant4.cxx:2:
In file included from /Users/mato/.julia/artifacts/b280a0aa921f80d29071186c9d93766a8c683ca7/include/jlcxx/jlcxx.hpp:15:
/Users/mato/.julia/artifacts/b280a0aa921f80d29071186c9d93766a8c683ca7/include/jlcxx/module.hpp:123:20: error: call to deleted constructor of 'G4LogicalVolume'
  T* cpp_obj = new T(std::forward<ArgsT>(args)...);
                   ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/mato/.julia/artifacts/b280a0aa921f80d29071186c9d93766a8c683ca7/include/jlcxx/module.hpp:562:94: note: in instantiation of function template specialization
      'jlcxx::create<G4LogicalVolume, true, const G4LogicalVolume &>' requested here
    FunctionWrapperBase &new_wrapper = finalize ? method("dummy", [](ArgsT... args) { return create<T, true>(args...); }) : method("dummy", [](ArgsT... args) { return create<T...
                                                                                             ^
/Users/mato/.julia/artifacts/b280a0aa921f80d29071186c9d93766a8c683ca7/include/jlcxx/module.hpp:986:16: note: in instantiation of function template specialization
      'jlcxx::Module::constructor<G4LogicalVolume, const G4LogicalVolume &>' requested here
      m_module.constructor<T, ArgsT...>(m_dt, finalize);
               ^
/Users/mato/Development/Julia/Geant4.jl/gen/cpp/jlGeant4.cxx:3394:7: note: in instantiation of function template specialization 'jlcxx::TypeWrapper<G4LogicalVolume>::constructor<const
      G4LogicalVolume &>' requested here
  t18.constructor<const G4LogicalVolume &>(/*finalize=*/true);
      ^
/Users/mato/Development/views/dev4/x86_64-mac11-clang120-opt/include/Geant4/G4LogicalVolume.hh:204:5: note: 'G4LogicalVolume' has been explicitly marked deleted here
    G4LogicalVolume(const G4LogicalVolume&) = delete;

Fix in #13

Commit d65259 provides a more general fix and includes a unit test to catch similar issues.