From 776d674ed0434d6b6803cdf4f513bea5e614bfc5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 23 Feb 2021 10:39:35 -0700 Subject: [PATCH] Provide compile-time error messages if we don't handle a type. --- include/deal.II/base/hdf5.h | 43 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) 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 {}; } -- 2.39.5