Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [[nodiscard]] to cpp #3279

Merged
merged 10 commits into from
Dec 17, 2024
Merged

Conversation

bernardnormier
Copy link
Member

This PR adds [[nodiscard]] to many C++ API. It's largely an automatic update using clang-tidy -fix.

I disabled modernize-use-nodiscard for a single API: ice_getConnection on proxy, which is often used in our tests to establish a connection without actually retrieving the connection.

The addition of nodiscard also unveiled two bugs (in an IceGrid test and in IcePy). Both fixed by this PR.

cpp/include/DataStorm/InternalI.h Show resolved Hide resolved
cpp/include/DataStorm/InternalI.h Show resolved Hide resolved
cpp/include/DataStorm/InternalI.h Show resolved Hide resolved
cpp/include/DataStorm/InternalI.h Show resolved Hide resolved
cpp/include/Ice/Service.h Outdated Show resolved Hide resolved
@@ -43,24 +43,24 @@ namespace IceInternal
// This is called from the endpoint host resolver thread, so
// it's safe if this this method blocks.
//
virtual NetworkProxyPtr resolveHost(ProtocolSupport) const = 0;
[[nodiscard]] virtual NetworkProxyPtr resolveHost(ProtocolSupport) const = 0;
Copy link
Member

Choose a reason for hiding this comment

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

What is the rule for this attribute, we apply it to the initial declaration and to the overrides? It isn't enough to just apply it to the initial declaration?

Copy link
Member

@externl externl left a comment

Choose a reason for hiding this comment

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

Looks good. I find the API usage of getInfo not great.

@@ -63,7 +63,7 @@ ConnectionManager::remove(const Ice::ConnectionPtr& connection)
exception_ptr ex;
try
{
connection->getInfo();
[[maybe_unused]] auto _ = connection->getInfo();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not following this code. Doesn't getInfo only throw if the connection is closed. Are we relying on this behavior to get the close exception?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's apparently what we do, yes. However, I am not following this code either.

@bernardnormier bernardnormier merged commit b6d18ff into zeroc-ice:main Dec 17, 2024
20 checks passed
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

3 participants