Skip to content

Improve archive destruction#878

Open
jarzec wants to merge 1 commit intoUSCiLab:masterfrom
jarzec:improve-archive-dtors
Open

Improve archive destruction#878
jarzec wants to merge 1 commit intoUSCiLab:masterfrom
jarzec:improve-archive-dtors

Conversation

@jarzec
Copy link
Contributor

@jarzec jarzec commented Mar 6, 2026

The destructors of the JSON and the XML archive may throw despite being declared noexcept. This may lead to potential issues including std::terminate() being called if an exception is thrown during unwinding see the Core Guidelines: C.36: A destructor must not fail.

This problem is addressed following the pattern analogous the one used used e.g. in std::stream: add (potentially throwing) close() method that allows clients to handle the potential exceptions. Make the destructor silently swallow any exception.

This addresses the issue #822.

The destructors of the JSON and the XML archive may throw despite being
declared `noexcept`. This is addressed following the pattern used e.g.
in std::stream: add (potentilally throwing) `close()` method that allows
clients to handle the potential exceptions. Make the destructor silently
swallow any exception.
@jarzec
Copy link
Contributor Author

jarzec commented Mar 8, 2026

@AzothAmmo The only CI failure for this PR is due to the error:
Could not find Xcode version that satisfied version spec: '15'.

The macos-latest runner is version 15 and it does not provide XCode 15 (it defaults to 16 which is the lowest on that runner).
The easiest way to test with XCode 15 seems to be running on a macos-14 runner (which defaults to XCode v15).

@jarzec jarzec mentioned this pull request Mar 10, 2026

//! Destructor, flushes the JSON
~JSONOutputArchive() CEREAL_NOEXCEPT
//! Explicitly finishes the JSON output and flushes to the stream
Copy link
Contributor

Choose a reason for hiding this comment

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

By allowing this to be called outside of the destructor it does open up a case where the user calls close() then attempts to use the archive again. Have you tested what happens when this occurs? At minimum the description should mention that the archive will enter into undefined territory after calling this and further using the archive. I don't really want to put an overhead of checking against itsClosed to save the user in this case, as this is probably an off-nominal use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants