From: Wolfgang Bangerth Date: Tue, 23 Feb 2021 17:39:35 +0000 (-0700) Subject: Provide compile-time error messages if we don't handle a type. X-Git-Tag: v9.3.0-rc1~420^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11797%2Fhead;p=dealii.git Provide compile-time error messages if we don't handle a type. --- diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index c24dc47780..57e89492f8 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -1249,7 +1249,15 @@ namespace HDF5 std::shared_ptr get_hdf5_datatype() { - std::shared_ptr t_type; + static_assert(std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same>::value || + std::is_same>::value, + "The data type you are trying to get the HDF5 tag for " + "is not supported by this function."); + if (std::is_same::value) { return std::make_shared(H5T_NATIVE_FLOAT); @@ -1268,13 +1276,15 @@ namespace HDF5 } else if (std::is_same>::value) { - t_type = std::shared_ptr(new hid_t, [](hid_t *pointer) { - // Release the HDF5 resource - const herr_t ret = H5Tclose(*pointer); - AssertNothrow(ret >= 0, ExcInternalError()); - (void)ret; - delete pointer; - }); + std::shared_ptr t_type = + std::shared_ptr(new hid_t, [](hid_t *pointer) { + // Release the HDF5 resource + const herr_t ret = H5Tclose(*pointer); + AssertNothrow(ret >= 0, ExcInternalError()); + (void)ret; + delete pointer; + }); + *t_type = H5Tcreate(H5T_COMPOUND, sizeof(std::complex)); // The C++ standards committee agreed to mandate that the storage // format used for the std::complex type be binary-compatible with @@ -1289,13 +1299,14 @@ namespace HDF5 } else if (std::is_same>::value) { - t_type = std::shared_ptr(new hid_t, [](hid_t *pointer) { - // Release the HDF5 resource - const herr_t ret = H5Tclose(*pointer); - AssertNothrow(ret >= 0, ExcInternalError()); - (void)ret; - delete pointer; - }); + std::shared_ptr t_type = + std::shared_ptr(new hid_t, [](hid_t *pointer) { + // Release the HDF5 resource + const herr_t ret = H5Tclose(*pointer); + AssertNothrow(ret >= 0, ExcInternalError()); + (void)ret; + delete pointer; + }); *t_type = H5Tcreate(H5T_COMPOUND, sizeof(std::complex)); // The C++ standards committee agreed to mandate that the storage // format used for the std::complex type be binary-compatible with @@ -1311,7 +1322,7 @@ namespace HDF5 // The function should not reach this point Assert(false, ExcInternalError()); - return t_type; + return {}; }