Skip to content

Commit

Permalink
C++ warning and build fixes (#707)
Browse files Browse the repository at this point in the history
* Committing clang-format changes

* C++ build and warning updates

* Fixes all warnings on C++ (with gcc 9.3)
* Updates CMake and Autotools C++ builds

* Undo warning clobber

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
derobins and github-actions[bot] authored Jun 1, 2021
1 parent 4ef33ef commit 50d0888
Show file tree
Hide file tree
Showing 39 changed files with 453 additions and 651 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@ if (EXISTS "${HDF5_SOURCE_DIR}/c++" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/c++")
endif ()
endif ()

include (${HDF_RESOURCES_EXT_DIR}/HDFUseCXX.cmake)
include (${HDF_RESOURCES_DIR}/HDFCXXCompilerFlags.cmake)

add_subdirectory (c++)
Expand Down
5 changes: 1 addition & 4 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
./.github/workflows/main.yml _DO_NOT_DISTRIBUTE_
./.github/workflows/pr-check.yml _DO_NOT_DISTRIBUTE_

./m4/aclocal_cxx.m4
./m4/aclocal_fc.m4
./m4/aclocal_fc.f90
./m4/ax_check_class.m4
Expand Down Expand Up @@ -172,6 +171,7 @@
./config/gnu-warnings/cxx-4.8
./config/gnu-warnings/cxx-4.9
./config/gnu-warnings/cxx-5
./config/gnu-warnings/cxx-9
./config/gnu-warnings/cxx-error-5
./config/gnu-warnings/cxx-error-general
./config/gnu-warnings/cxx-noerror-5
Expand Down Expand Up @@ -3546,7 +3546,6 @@
./config/cmake/CTestCustom.cmake
./config/cmake/fileCompareTest.cmake
./config/cmake/FindHDFS.cmake
./config/cmake/H5cxx_config.h.in
./config/cmake/H5pubconf.h.in
./config/cmake/hdf5-config.cmake.in
./config/cmake/hdf5-config-version.cmake.in
Expand Down Expand Up @@ -3581,11 +3580,9 @@
./config/cmake_ext_mod/hdf.bmp
./config/cmake_ext_mod/hdf.icns
./config/cmake_ext_mod/hdf.ico
./config/cmake_ext_mod/HDFCXXTests.cpp
./config/cmake_ext_mod/HDFLibMacros.cmake
./config/cmake_ext_mod/HDFMacros.cmake
./config/cmake_ext_mod/HDFTests.c
./config/cmake_ext_mod/HDFUseCXX.cmake
./config/cmake_ext_mod/HDFUseFortran.cmake
./config/cmake_ext_mod/NSIS.InstallOptions.ini.in
./config/cmake_ext_mod/NSIS.template.in
Expand Down
7 changes: 0 additions & 7 deletions c++/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
cmake_minimum_required (VERSION 3.12)
project (HDF5_CPP_SRC CXX)

#-----------------------------------------------------------------------------
# Generate configure file
#-----------------------------------------------------------------------------
configure_file (${HDF_RESOURCES_DIR}/H5cxx_config.h.in
${HDF5_SRC_BINARY_DIR}/H5cxx_pubconf.h
)

#-----------------------------------------------------------------------------
# Define cpp Library
#-----------------------------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions c++/src/H5Cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,4 @@
#include "H5File.h"
#include "H5Library.h"

/* Some C++ compilers do not have offsetof macro; define to bypass the problem
- BMR- -EIP- 2007/08/01
*/
#ifndef H5_CXX_HAVE_OFFSETOF
#ifdef HOFFSET
#undef HOFFSET
#endif
#define HOFFSET(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
#endif

#endif // H5Cpp_H
7 changes: 3 additions & 4 deletions c++/src/H5DataSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ const DataSpace &DataSpace::ALL = *getConstant();
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataSpace::DataSpace(H5S_class_t type) : IdComponent()
DataSpace::DataSpace(H5S_class_t type) : IdComponent(), id{H5Screate(type)}
{
id = H5Screate(type);
if (id < 0) {
throw DataSpaceIException("DataSpace constructor", "H5Screate failed");
}
Expand All @@ -105,9 +104,9 @@ DataSpace::DataSpace(H5S_class_t type) : IdComponent()
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataSpace::DataSpace(int rank, const hsize_t *dims, const hsize_t *maxdims) : IdComponent()
DataSpace::DataSpace(int rank, const hsize_t *dims, const hsize_t *maxdims)
: IdComponent(), id{H5Screate_simple(rank, dims, maxdims)}
{
id = H5Screate_simple(rank, dims, maxdims);
if (id < 0) {
throw DataSpaceIException("DataSpace constructor", "H5Screate_simple failed");
}
Expand Down
24 changes: 11 additions & 13 deletions c++/src/H5DataType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ DataType::DataType(const hid_t existing_id) : H5Object(), id(existing_id), encod
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataType::DataType(const H5T_class_t type_class, size_t size) : H5Object(), encoded_buf(NULL), buf_size(0)
DataType::DataType(const H5T_class_t type_class, size_t size)
: H5Object(), id{H5Tcreate(type_class, size)}, encoded_buf(NULL), buf_size(0)
{
// Call C routine to create the new datatype
id = H5Tcreate(type_class, size);
if (id < 0) {
throw DataTypeIException("DataType constructor", "H5Tcreate failed");
}
Expand All @@ -97,9 +96,10 @@ DataType::DataType(const H5T_class_t type_class, size_t size) : H5Object(), enco
// Programmer Binh-Minh Ribler - Oct, 2006
//--------------------------------------------------------------------------
DataType::DataType(const H5Location &loc, const void *ref, H5R_type_t ref_type, const PropList &plist)
: H5Object(), encoded_buf(NULL), buf_size(0)
: H5Object(), id{H5Location::p_dereference(loc.getId(), ref, ref_type, plist,
"constructor - by dereference")},
encoded_buf(NULL), buf_size(0)
{
id = H5Location::p_dereference(loc.getId(), ref, ref_type, plist, "constructor - by dereference");
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -146,10 +146,9 @@ DataType::DataType(const DataType &original) : H5Object(), id(original.id), enco
// unnecessarily and will produce undefined behavior.
// -BMR, Apr 2015
//--------------------------------------------------------------------------
DataType::DataType(const PredType &pred_type) : H5Object(), encoded_buf(NULL), buf_size(0)
DataType::DataType(const PredType &pred_type)
: H5Object(), id{H5Tcopy(pred_type.getId())}, encoded_buf(NULL), buf_size(0)
{
// Call C routine to copy the datatype
id = H5Tcopy(pred_type.getId());
if (id < 0)
throw DataTypeIException("DataType constructor", "H5Tcopy failed");
}
Expand All @@ -168,9 +167,9 @@ DataType::DataType(const PredType &pred_type) : H5Object(), encoded_buf(NULL), b
// improve usability.
// -BMR, Dec 2016
//--------------------------------------------------------------------------
DataType::DataType(const H5Location &loc, const char *dtype_name) : H5Object(), encoded_buf(NULL), buf_size(0)
DataType::DataType(const H5Location &loc, const char *dtype_name)
: H5Object(), id{p_opentype(loc, dtype_name)}, encoded_buf(NULL), buf_size(0)
{
id = p_opentype(loc, dtype_name);
}

//--------------------------------------------------------------------------
Expand All @@ -188,9 +187,8 @@ DataType::DataType(const H5Location &loc, const char *dtype_name) : H5Object(),
// -BMR, Dec 2016
//--------------------------------------------------------------------------
DataType::DataType(const H5Location &loc, const H5std_string &dtype_name)
: H5Object(), encoded_buf(NULL), buf_size(0)
: H5Object(), id{p_opentype(loc, dtype_name.c_str())}, encoded_buf(NULL), buf_size(0)
{
id = p_opentype(loc, dtype_name.c_str());
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -318,7 +316,7 @@ DataType::encode()

// Allocate buffer and call C function again to encode
if (buf_size > 0) {
encoded_buf = (unsigned char *)HDcalloc((size_t)1, buf_size);
encoded_buf = static_cast<unsigned char *>(HDcalloc(1, buf_size));
ret_value = H5Tencode(id, encoded_buf, &buf_size);
if (ret_value < 0) {
throw DataTypeIException("DataType::encode", "H5Tencode failed");
Expand Down
4 changes: 2 additions & 2 deletions c++/src/H5DxferProp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ DSetMemXferPropList::getBuffer(void **tconv, void **bkg) const
void
DSetMemXferPropList::setPreserve(bool status) const
{
herr_t ret_value = H5Pset_preserve(id, (hbool_t)status);
herr_t ret_value = H5Pset_preserve(id, static_cast<hbool_t>(status));
if (ret_value < 0) {
throw PropListIException("DSetMemXferPropList::setPreserve", "H5Pset_preserve failed");
}
Expand Down Expand Up @@ -314,7 +314,7 @@ DSetMemXferPropList::getDataTransform() const
H5std_string expression;

// Preliminary call to get the expression's length
ssize_t exp_len = H5Pget_data_transform(id, NULL, (size_t)0);
ssize_t exp_len = H5Pget_data_transform(id, NULL, 0);

// If H5Pget_data_transform returns a negative value, raise an exception
if (exp_len < 0) {
Expand Down
2 changes: 1 addition & 1 deletion c++/src/H5Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const char Exception::DEFAULT_MSG[] = "No detailed information provided";
///\brief Default constructor.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
Exception::Exception()
Exception::Exception() : detail_message{""}, func_name{""}
{
}

Expand Down
6 changes: 2 additions & 4 deletions c++/src/H5File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ H5File::p_get_file(const char *name, unsigned int flags, const FileCreatPropList
// constructor is needed by the library in order to return
// an object, H5File doesn't need it. -BMR (HDFFV-8766 partially)
//--------------------------------------------------------------------------
H5File::H5File(hid_t existing_id) : Group()
H5File::H5File(hid_t existing_id) : Group(), id{existing_id}
{
id = existing_id;
incRefCount(); // increment number of references to this id
}

Expand All @@ -180,9 +179,8 @@ H5File::H5File(hid_t existing_id) : Group()
///\param original - IN: H5File instance to copy
// December 2000
//--------------------------------------------------------------------------
H5File::H5File(const H5File &original) : Group(original)
H5File::H5File(const H5File &original) : Group(original), id{original.getId()}
{
id = original.getId();
incRefCount(); // increment number of references to this id
}

Expand Down
4 changes: 2 additions & 2 deletions c++/src/H5LcreatProp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ LinkCreatPropList::LinkCreatPropList(const hid_t plist_id) : PropList(plist_id)
void
LinkCreatPropList::setCreateIntermediateGroup(bool crt_intmd_group) const
{
herr_t ret_value = H5Pset_create_intermediate_group(id, (unsigned)crt_intmd_group);
herr_t ret_value = H5Pset_create_intermediate_group(id, static_cast<unsigned>(crt_intmd_group));
// Throw exception if H5Pset_create_intermediate_group returns failure
if (ret_value < 0) {
throw PropListIException("setCreateIntermediateGroup", "H5Pset_create_intermediate_group failed");
Expand All @@ -146,7 +146,7 @@ LinkCreatPropList::getCreateIntermediateGroup() const
throw PropListIException("getCreateIntermediateGroup", "H5Pget_create_intermediate_group failed");
}

return ((bool)crt_intmd_group);
return static_cast<bool>(crt_intmd_group);
}

//--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion c++/src/H5Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ H5Location::getComment(const char *name, size_t buf_size) const
H5std_string comment;

// Preliminary call to get the comment's length
ssize_t comment_len = H5Oget_comment_by_name(getId(), name, NULL, (size_t)0, H5P_DEFAULT);
ssize_t comment_len = H5Oget_comment_by_name(getId(), name, NULL, 0, H5P_DEFAULT);

// If H5Oget_comment_by_name returns a negative value, raise an exception
if (comment_len < 0) {
Expand Down
8 changes: 3 additions & 5 deletions c++/src/H5PropList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ PropList::PropList(const PropList &original) : IdComponent(), id(original.id)
// property's id to H5P_DEFAULT.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
PropList::PropList(const hid_t plist_id) : IdComponent()
PropList::PropList(const hid_t plist_id) : IdComponent(), id{H5P_DEFAULT}
{
if (plist_id <= 0)
id = H5P_DEFAULT;

H5I_type_t id_type = H5Iget_type(plist_id);
switch (id_type) {
case H5I_GENPROP_CLS:
Expand Down Expand Up @@ -633,11 +630,12 @@ PropList::setProperty(const char *name, void *value) const
void
PropList::setProperty(const char *name, const char *charptr) const
{
herr_t ret_value = H5Pset(id, name, (const void *)charptr);
herr_t ret_value = H5Pset(id, name, static_cast<const void *>(charptr));
if (ret_value < 0) {
throw PropListIException(inMemFunc("setProperty"), "H5Pset failed");
}
}

//--------------------------------------------------------------------------
// Function: PropList::setProperty
///\brief This is an overloaded member function, provided for convenience.
Expand Down
Loading

0 comments on commit 50d0888

Please sign in to comment.