Skip to content

IOTask: AbstractParameter Slice Safety#410

Merged
ax3l merged 1 commit intoopenPMD:devfrom
ax3l:topic-modernizeTaskMakeShared
Jan 8, 2019
Merged

IOTask: AbstractParameter Slice Safety#410
ax3l merged 1 commit intoopenPMD:devfrom
ax3l:topic-modernizeTaskMakeShared

Conversation

@ax3l
Copy link
Member

@ax3l ax3l commented Jan 5, 2019

The IOTask constructor caused problems with Clang 4.0.1 on OSX, where the Parameter< Operation::CREATE_FILE > does seem not to copy the name member. Thanks to @mingwandroid for first seeing this and debugging a lot with me!

It turns out that we copy the AbstractParameter base class, which leads to object slicing.
Probably implicit copy constructors are weirdly handled in this old Clang version, so we make them explicitly deleted as the core guidelines recommend.

Also, IOTasks might better have an explicit copy constructor since we copy it around (std::queue::push(), etc.)

https://stackoverflow.com/questions/274626/what-is-object-slicing
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-copy-virtual
https://en.wikipedia.org/wiki/Object_slicing

@ax3l ax3l force-pushed the topic-modernizeTaskMakeShared branch 5 times, most recently from 58832c3 to 2b6123f Compare January 8, 2019 06:57
Parameter< op > const& p)
: writable{w},
operation{op},
parameter{new Parameter< op >(p)}
Copy link
Member Author

@ax3l ax3l Jan 8, 2019

Choose a reason for hiding this comment

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

Copy link
Member Author

@ax3l ax3l Jan 8, 2019

Choose a reason for hiding this comment

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

Hm, but since we explicitly new on the Parameter< op > this should not be slicing...
At least clang-tidy-6.0 does not find it as such:

clang-tidy-6.0 test.cpp -checks='*,cppcoreguidelines-slicing' --

Could still be an AppleClang compiler bug that optimizes it to one.

Copy link
Member Author

@ax3l ax3l Jan 8, 2019

Choose a reason for hiding this comment

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

Nah, it is likely still slicing since we push IOTasks into std::qeues ... but they are only copies of shared_ptrs of AbstractParameter, so no copy.

Maybe it's just a compiler bug with the implicit/explicit copy constructors. Now it's safe.

@ax3l ax3l changed the title IOTask: make_shared IOTask: AbstractParameter Object Slicing Jan 8, 2019
@ax3l ax3l force-pushed the topic-modernizeTaskMakeShared branch from 2b6123f to a981d4a Compare January 8, 2019 09:27
@@ -235,22 +440,22 @@ class IOTask
*/
template< Operation op >
IOTask(Writable* w,
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe also make explicitto avoid unintentional implicit conversions

{ }

template< Operation op >
IOTask(Attributable* a,
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe also make explicitto avoid unintentional implicit conversions

@ax3l ax3l added the machine/system machine & HPC system specific issues label Jan 8, 2019
@ax3l ax3l force-pushed the topic-modernizeTaskMakeShared branch from a981d4a to 04fcf11 Compare January 8, 2019 10:24
@ax3l ax3l changed the title IOTask: AbstractParameter Object Slicing IOTask: AbstractParameter Slice Safety Jan 8, 2019
@ax3l ax3l requested a review from anokfireball January 8, 2019 11:04
@ax3l ax3l force-pushed the topic-modernizeTaskMakeShared branch from 04fcf11 to 0aadc0d Compare January 8, 2019 11:24
Copy link
Member Author

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Maybe copy shared pointer as {other.parameters} (really share ownership by value)

The IOTask constructor caused problems with Clang 4.0.1 on OSX,
where the `Parameter< Operation::CREATE_FILE >` does seem not to
copy the `name` member.
Thanks to Ray Donnelly for first seeing this!

~~It turns out that we copy the `AbstractParameter` base class,
which leads to object slicing.~~
Probably implicit copy constructors are weirdly handled in this
old Clang version, so we make them explicitly deleted as the
core guidelines recommend.

Also, `IOTasks` might better have an explicit copy constructor
since we copy it around (`std::queue::push()`, etc.)

https://stackoverflow.com/questions/274626/what-is-object-slicing
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-copy-virtual
https://en.wikipedia.org/wiki/Object_slicing
@ax3l ax3l force-pushed the topic-modernizeTaskMakeShared branch from 0aadc0d to 31a91f7 Compare January 8, 2019 12:09
@ax3l ax3l merged commit 8fbe2c4 into openPMD:dev Jan 8, 2019
@ax3l ax3l deleted the topic-modernizeTaskMakeShared branch January 8, 2019 13:42
@ax3l ax3l mentioned this pull request May 22, 2019
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

machine/system machine & HPC system specific issues refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant