multiscale / muscle3

The third major version of the MUltiScale Coupling Library and Environment
Apache License 2.0
25 stars 13 forks source link

Compiler warning about implicit Data copy constructor #258

Closed LourensVeen closed 1 year ago

LourensVeen commented 1 year ago

Modern compilers complain about Data having a user-defined assignment operator but not a user-defined copy constructor:

In file included from ../../lib/muscle3/muscle3/include/libmuscle/data.hpp:867,
                 from ../../lib/muscle3/muscle3/include/libmuscle/libmuscle.hpp:4,
                 from adhesions_muscle3.cpp:44:
../../lib/muscle3/muscle3/include/libmuscle/data.tpp: In instantiation of ‘static libmuscle::impl::Data libmuscle::impl::Data::dict(const Args& ...) [with Args = {char [7], libmuscle::impl::Data, char [5], libmuscle::impl::Data}]’:
adhesions_muscle3.cpp:210:35:   required from here
../../lib/muscle3/muscle3/include/libmuscle/data.tpp:68:12: warning: implicitly-declared ‘libmuscle::impl::Data::Data(const libmuscle::impl::Data&)’ is deprecated [-Wdeprecated-copy]
   68 |     return dict;
      |            ^~~~
In file included from ../../lib/muscle3/muscle3/include/libmuscle/libmuscle.hpp:4,
                 from adhesions_muscle3.cpp:44:
../../lib/muscle3/muscle3/include/libmuscle/data.hpp:749:16: note: because ‘libmuscle::impl::Data’ has user-provided ‘libmuscle::impl::Data& libmuscle::impl::Data::operator=(const libmuscle::impl::Data&)’
  749 |         Data & operator=(Data const & rhs);
      |                ^~~~~~~~

It's not actually a bug in this case, but the compiler doesn't know that. We should probably just add a user-defined copy-constructor that does what the default one does just to reassure the compiler. We should check whether we need a destructor too, because of the rule-of-three.

LourensVeen commented 1 year ago

Actually, it doesn't have to be that modern a compiler it seems, you just need to use -Wextra. We don't, but a user might and since this is in a public header, we should fix it.

LourensVeen commented 1 year ago

Fix released with version 0.7.1.