Ubuntu 19.10 GCC 9 HDF5 10.4 -Wextra software using HDF5 fails to build with error: implicitly-declared 'H5::H5File& H5::H5File::operator=(const H5::H5File&)' is deprecated [-Werror=deprecated-copy]"


#1

The gem5 project uses HDF5, and I noticed that the build failed on Ubuntu 19.10 because of GCC 9 getting more strict error checking than before: https://gem5.atlassian.net/browse/GEM5-365

The problem can be reproduced with:

#include <H5Cpp.h>

int main (void) {
    H5::H5File h5File;
    h5File = H5::H5File("asdf", H5F_ACC_TRUNC);
}

with:

g++ -Werror -Wdeprecated-copy -I/usr/include/hdf5/serial -std=c++11 -o hello_cpp.out hello_cpp.cpp -lhdf5_cpp -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lhdf5

which fails as:

main.cpp: In function ‘int main()’:
main.cpp:5:46: error: implicitly-declared ‘H5::H5File& H5::H5File::operator=(const H5::H5File&)’ is deprecated [-Werror=deprecated-copy]
    5 |     h5File = H5::H5File("asdf", H5F_ACC_TRUNC);
      |                                              ^
In file included from /usr/include/hdf5/serial/H5Cpp.h:48,
                 from main.cpp:1:
/usr/include/hdf5/serial/H5File.h:101:9: note: because ‘H5::H5File’ has user-provided ‘H5::H5File::H5File(const H5::H5File&)’
  101 |         H5File(const H5File& original);
      |         ^~~~~~
/usr/include/hdf5/serial/H5File.h: In member function ‘H5::H5File& H5::H5File::operator=(const H5::H5File&)’:
/usr/include/hdf5/serial/H5File.h:25:17: error: implicitly-declared ‘H5::Group& H5::Group::operator=(const H5::Group&)’ is deprecated [-Werror=deprecated-copy]
   25 | class H5_DLLCPP H5File : public Group {
      |                 ^~~~~~
In file included from /usr/include/hdf5/serial/H5Cpp.h:47,
                 from main.cpp:1:
/usr/include/hdf5/serial/H5Group.h:57:9: note: because ‘H5::Group’ has user-provided ‘H5::Group::Group(const H5::Group&)’
   57 |         Group(const Group& original);
      |         ^~~~~
main.cpp: In function ‘int main()’:
main.cpp:5:46: note: synthesized method ‘H5::H5File& H5::H5File::operator=(const H5::H5File&)’ first required here
    5 |     h5File = H5::H5File("asdf", H5F_ACC_TRUNC);
      |                                              ^
cc1plus: all warnings being treated as errors

-Wdeprecated-copy is implied by -Wextra, and therefore common.

The problem is that the H5File class is not implementing the rule of five: https://en.cppreference.com/w/cpp/language/rule_of_three

I could submit a pull request if someone promises to review it, but it would likely be much easier for someone from the project to fix this trivial issue :slight_smile:


#2

Hi Ciro,

Thank you for reporting the issue. We will fix it.


#3

Has this issue been resolved? is a release? or is there a patch?