Skip to content

Commit 44f1382

Browse files
committed
Avoid some wrong compiler warnings (gcc14)
1 parent 2d72c34 commit 44f1382

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

examples/8b_benchmark_read_parallel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,14 @@ class TestInput
456456
return;
457457
Timer blockTime(s.str(), m_MPIRank);
458458

459-
Offset off(meshExtent.size(), 0);
460-
Extent ext(meshExtent.size(), 1);
459+
// Avoid the below forms due to a compiler bug on gcc14
460+
// warning: 'void operator delete(void*, std::size_t)' called on pointer
461+
// '<unknown>' with nonzero offset [1, 9223372036854775800] Offset
462+
// off(meshExtent.size(), 0); Extent ext(meshExtent.size(), 1);
463+
Offset off(meshExtent.size());
464+
Extent ext(meshExtent.size());
465+
std::fill(off.begin(), off.end(), 0);
466+
std::fill(ext.begin(), ext.end(), 1);
461467

462468
for (unsigned int i = 0; i < meshExtent.size(); i++)
463469
{
@@ -486,7 +492,7 @@ class TestInput
486492
}
487493
}
488494

489-
auto prettyLambda = [&](Offset oo, Extent cc) {
495+
auto prettyLambda = [&](Offset const &oo, Extent const &cc) {
490496
std::ostringstream o;
491497
o << "[ ";
492498
std::ostringstream c;

include/openPMD/snapshots/ContainerImpls.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ class StatefulSnapshotsContainer : public AbstractSnapshotsContainer
3434
* make_reading_stateful_iterator.
3535
* The iterator is resolved upon calling get() below.
3636
*/
37-
std::variant<std::function<StatefulIterator *()>, StatefulIterator *>
38-
m_bufferedIterator;
37+
38+
// Need to put the deferred function behind a shared_ptr to avoid a
39+
// gcc14 compiler bug
40+
// warning: '*(std::_Function_base*)((char*)this +
41+
// 8).std::_Function_base::_M_manager' may be used uninitialized
42+
using Deferred_t = std::shared_ptr<std::function<StatefulIterator *()>>;
43+
using Evaluated_t = StatefulIterator *;
44+
using BufferedIterator_t = std::variant<Deferred_t, Evaluated_t>;
45+
BufferedIterator_t m_bufferedIterator = nullptr;
3946
};
4047
Members members;
4148

src/snapshots/ContainerImpls.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ namespace openPMD
1414
{
1515
StatefulSnapshotsContainer::StatefulSnapshotsContainer(
1616
std::variant<std::function<StatefulIterator *()>, StatefulIterator *> begin)
17-
: members{std::move(begin)}
17+
: members{
18+
// Need to put the deferred function behind a shared_ptr to avoid a
19+
// gcc14 compiler bug
20+
// warning: '*(std::_Function_base*)((char*)this +
21+
// 8).std::_Function_base::_M_manager' may be used uninitialized
22+
std::visit(
23+
auxiliary::overloaded{
24+
[](std::function<StatefulIterator *()> &&f)
25+
-> Members::BufferedIterator_t {
26+
return std::make_shared<
27+
Members::Deferred_t::element_type>(std::move(f));
28+
},
29+
[](StatefulIterator *it) -> Members::BufferedIterator_t {
30+
return it;
31+
}},
32+
std::move(begin))}
1833
{}
1934

2035
StatefulSnapshotsContainer::StatefulSnapshotsContainer(
@@ -33,21 +48,19 @@ auto StatefulSnapshotsContainer::get() -> StatefulIterator *
3348
{
3449
return std::visit(
3550
auxiliary::overloaded{
36-
[this](
37-
std::function<StatefulIterator *()> &deferred_initialization) {
38-
auto it = deferred_initialization();
51+
[this](Members::Deferred_t &deferred_initialization) {
52+
auto it = (*deferred_initialization)();
3953
this->members.m_bufferedIterator = it;
4054
return it;
4155
},
42-
[](StatefulIterator *it) { return it; }},
56+
[](Members::Evaluated_t it) { return it; }},
4357
members.m_bufferedIterator);
4458
}
4559
auto StatefulSnapshotsContainer::get() const -> StatefulIterator const *
4660
{
4761
return std::visit(
4862
auxiliary::overloaded{
49-
[](std::function<StatefulIterator *()> const &)
50-
-> StatefulIterator const * {
63+
[](Members::Deferred_t const &) -> StatefulIterator const * {
5164
throw std::runtime_error(
5265
"[StatefulSnapshotscontainer] Initialization has been "
5366
"deferred, but container is accessed as const, so cannot "

0 commit comments

Comments
 (0)