Skip to content

Fixed a problem where AlwaysAssert macro does not like std::unique_pt…#52

Merged
VoronkovMA merged 1 commit intocasacore:masterfrom
vuo006:master
Mar 27, 2026
Merged

Fixed a problem where AlwaysAssert macro does not like std::unique_pt…#52
VoronkovMA merged 1 commit intocasacore:masterfrom
vuo006:master

Conversation

@vuo006
Copy link
Copy Markdown
Contributor

@vuo006 vuo006 commented Mar 26, 2026

The compiler error message generated for this problem is shown below:

casacore/casa/Utilities/Assert.h:156:36: error: no matching function for call to ‘casacore::assert_casacore::AipsError::assert_(std::unique_ptrcasacore::CoordinateSystem&, const char [35], const char [107], casacore::Int)’
156 | {casacore::assert_ dummy_(expr, "Failed AlwaysAssert " #expr,FILE,(casacore::Int)LINE); dummy_.null(); }

casarest/synthesis/Images//ADIOSImage.tcc:289:3: note: in expansion of macro ‘AlwaysAssert’
289 | AlwaysAssert(restoredCoords, casacore::AipsError);

@VoronkovMA VoronkovMA self-requested a review March 26, 2026 00:50
@VoronkovMA
Copy link
Copy Markdown
Collaborator

Self-assigned myself as the reviewer again. I'm fine with the change (although doing it as a one-liner may look better). Ideally, we should push the explicit cast into casacore's AlwaysAssert (and other assert macros). Because casacore's code is old-ish and doesn't use smart pointers much, this issue hasn't surfaced before. But for now it is fine. I'll keep it open for a bit to let others comment. But otherwise, it is ready to merge.

Copy link
Copy Markdown
Collaborator

@VoronkovMA VoronkovMA left a comment

Choose a reason for hiding this comment

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

I'll repeat my in-code comment here because @vuo006 cannot see them for some reason. Although I'd personally prefer a one-liner AlwaysAssert(static_cast(restoredCoords)); if it is done with the intermediate assignment step, technically static_cast is not needed.

// written with raw pointers did the equivalent thing
std::unique_ptr<casacore::CoordinateSystem> restoredCoords(casacore::CoordinateSystem::restore(rec, "coords"));
AlwaysAssert(restoredCoords, casacore::AipsError);
const bool notNull = static_cast<bool>(restoredCoords);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

although personally I'd prefer a one-liner AlwaysAssert(static_cast(restoredCoords)); if you have it with the assignment step, you technically don't need the static_cast (it will cast automatically - this didn't work in the original code because the macro uses the type for the template type resolution)

@VoronkovMA VoronkovMA merged commit 7b76e2b into casacore:master Mar 27, 2026
2 checks passed
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