简体   繁体   中英

implicitly-declared ‘...’ is deprecated [-Wdeprecated-copy] in compiling TinyMT on GitHub

I have looked into similar questions on StackOverflow, but I couldn't figure out what to do.

The following is the error currently I face (some texts are in Japanese).

$ make
g++ -Wall -Wextra -O3  -I../include  -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -o tinymt32dc tinymt32dc.cpp parse_opt.o -lntl
次のファイルから読み込み:  tinymt32dc.cpp:29:
../include/search_all.hpp: In instantiation of ‘bool tinymt::all_in_one<T, G, ST, STLSB, SG>::search(G&, ST*, STLSB*, bool) [with T = unsigned int; G = tinymt::tinymt32; ST = MTToolBox::search_temper<tinymt::tinymt32, unsigned int, 32, 1, 23, 6>; STLSB = MTToolBox::search_temper<tinymt::tinymt32, unsigned int, 32, 1, 9, 5, true>; SG = MTToolBox::Sequential<unsigned int>]’:
tinymt32dc.cpp:84:16:   required from here
../include/search_all.hpp:92:20: 警告: implicitly-declared ‘constexpr tinymt::tinymt32& tinymt::tinymt32::operator=(const tinymt::tinymt32&)’ is deprecated [-Wdeprecated-copy]
   92 |               rand = s.get_random();
      |               ~~~~~^~~~~~~~~~~~~~~~
次のファイルから読み込み:  tinymt32dc.cpp:31:
tinymt32search.hpp:151:9: 備考: because ‘tinymt::tinymt32’ has user-provided ‘tinymt::tinymt32::tinymt32(const tinymt::tinymt32&)’
  151 |         tinymt32(const tinymt32& src) : param(src.param) {
      |         ^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: -lntl が見つかりません: No such file or directory
collect2: エラー: ld はステータス 1 で終了しました
make: *** [Makefile:23: tinymt32dc] エラー 1

I am not sure what I should fix.

I was compiling a program named "TinyMT" where you can see the source at the following URL.

https://github.com/MersenneTwister-Lab/TinyMT

My environment is Cygwin with the following packages (installed by Cygwin).

  • chere 1.4-1
  • gcc-core 11.3.0-1
  • gcc-g++ 11.3.0-1
  • gmpc 11.8.16-3
  • libgmp-devel 6.2.1-2
  • libgmpxx4 6.2.1-2
  • lzip 1.19-1
  • m4 1.4.19-1
  • make 4.3-1
  • perl 5.32.1-2

(Installation by myself, as far as I remember)

The warning says tinymt32 class has a user-defined copy constructor but there is no copy assignment operator defined. That is in violation of rule of three/five and signals potential troubles with management of any resources tinymt32 might hold.

So this warning is not targeted at the user of the library, but its author who forgot to define operator= or at least mark it default.

If you want to fix that class, do exactly that. If the default operator= is sufficient, add default -ed definition of it to the class. If you do not want to modify the library's code, there is not much you can do, maybe at least look whether it is safe to call this default implementation.

From my very brief look at the code, it just looks like copy ctor resets reverse_bit_flag while the implicit/default operator= will copy it from the source, not sure how relevant that is. But the class stores only values, no resources that need special care so the code should be reasonably safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM