Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Attribute
template <typename T, typename U>
auto doConvert(T *pv) -> U
{
(void)pv;
if constexpr (std::is_convertible_v<T, U>)
{
return static_cast<U>(*pv);
Expand All @@ -132,13 +133,15 @@ auto doConvert(T *pv) -> U
typename T::value_type,
typename U::value_type>)
{
U res;
U res{};
res.reserve(pv->size());
std::copy(pv->begin(), pv->end(), std::back_inserter(res));
return res;
}

throw std::runtime_error("getCast: no vector cast possible.");
else
{
throw std::runtime_error("getCast: no vector cast possible.");
}
}
// conversion cast: array to vector
// if a backend reports a std::array<> for something where
Expand All @@ -149,14 +152,16 @@ auto doConvert(T *pv) -> U
typename T::value_type,
typename U::value_type>)
{
U res;
U res{};
res.reserve(pv->size());
std::copy(pv->begin(), pv->end(), std::back_inserter(res));
return res;
}

throw std::runtime_error(
"getCast: no array to vector conversion possible.");
else
{
throw std::runtime_error(
"getCast: no array to vector conversion possible.");
}
}
// conversion cast: vector to array
// if a backend reports a std::vector<> for something where
Expand All @@ -167,7 +172,7 @@ auto doConvert(T *pv) -> U
typename T::value_type,
typename U::value_type>)
{
U res;
U res{};
if (res.size() != pv->size())
{
throw std::runtime_error(
Expand All @@ -180,28 +185,46 @@ auto doConvert(T *pv) -> U
}
return res;
}

throw std::runtime_error(
"getCast: no vector to array conversion possible.");
else
{
throw std::runtime_error(
"getCast: no vector to array conversion possible.");
}
}
// conversion cast: turn a single value into a 1-element vector
else if constexpr (auxiliary::IsVector_v<U>)
{
if constexpr (std::is_convertible_v<T, typename U::value_type>)
{
U res;
U res{};
res.reserve(1);
res.push_back(static_cast<typename U::value_type>(*pv));
return res;
}

throw std::runtime_error(
"getCast: no scalar to vector conversion possible.");
else
{
throw std::runtime_error(
"getCast: no scalar to vector conversion possible.");
}
}

(void)pv;
throw std::runtime_error("getCast: no cast possible.");
else
{
throw std::runtime_error("getCast: no cast possible.");
}
#if defined(__INTEL_COMPILER)
/*
* ICPC has trouble with if constexpr, thinking that return statements are
* missing afterwards. Deactivate the warning.
* Note that putting a statement here will not help to fix this since it will
* then complain about unreachable code.
* https://community.intel.com/t5/Intel-C-Compiler/quot-if-constexpr-quot-and-quot-missing-return-statement-quot-in/td-p/1154551
*/
#pragma warning(disable : 1011)
}
#pragma warning(default : 1011)
#else
}
#endif

/** Retrieve a stored specific Attribute and cast if convertible.
*
Expand Down
13 changes: 13 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ TEST_CASE("available_chunks_test_json", "[serial][json]")

TEST_CASE("multiple_series_handles_test", "[serial]")
{
/*
* clang also understands these pragmas.
*/
#if defined(__GNUC__MINOR__) || defined(__clang__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo fixed in #1255: __GNUC_MINOR__

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Copy link
Member

@ax3l ax3l Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this one set, you can remove -Wno-deprecated-declarations from quite a few CI scripts in .github/workflows/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> #1246

#endif
/*
* First test: No premature flushes through destructor when another copy
* is still around
Expand Down Expand Up @@ -456,6 +463,12 @@ TEST_CASE("multiple_series_handles_test", "[serial]")
*/
series_ptr->flush();
}
#if defined(__INTEL_COMPILER)
#pragma warning(disable : 2282)
#endif
#if defined(__GNUC__MINOR__) || defined(__clang__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

#pragma GCC diagnostic pop
#endif
}

void close_iteration_test(std::string file_ending)
Expand Down