Skip to content

tests: Fix ignored attributes warning during build #4670

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

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

LocutusOfBorg
Copy link
Contributor

Fix build warning.

@coveralls
Copy link

coveralls commented Feb 27, 2025

Coverage Status

coverage: 99.186%. remained the same
when pulling 7206a82 on LocutusOfBorg:fix-warning
into 8215dba on nlohmann:develop.

Signed-off-by: Gianfranco Costamagna <locutusofborg@debian.org>
Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

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

I fail to understand the reason for the change. decltype(&std::fclose) is supposed to be int (*)(FILE *), so why do you need to make this explicit and add a type alias?

@gregmarr
Copy link
Contributor

@nlohmann
Copy link
Owner

Thanks! So to silence GCC's warning about an ignored attribute, we define a unique pointer deleter type without that attribute and call this a fix, because GCC does not realize that we then instantiate this deleter with a function whose argument has an attribute?

@gregmarr
Copy link
Contributor

The warning is only on the template declaration, so moving it to the instantiation doesn't trigger that particular warning. They may expand it or add a new one in the future.

As described in the thread, below would be a better solution for size and performance if it were in the main library, but since it's in the tests, we're not as concerned about size and performance.

struct unique_ptr_fclose_deleter {
    void operator()(struct FILE* f) const {
        fclose(f);
    }
};
using FilePtr = std::unique_ptr<FILE, unique_ptr_fclose_deleter>;

Copy link
Owner

@nlohmann nlohmann 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 to me.

@nlohmann nlohmann added this to the Release 3.11.4 milestone Mar 24, 2025
@nlohmann
Copy link
Owner

Thanks for the clarification! I will merge this once #4701 is merged, because otherwise the CI would fail.

@nlohmann nlohmann merged commit cd92c09 into nlohmann:develop Mar 29, 2025
132 checks passed
@LocutusOfBorg LocutusOfBorg deleted the fix-warning branch March 31, 2025 15:43
@LocutusOfBorg
Copy link
Contributor Author

thanks!

@nlohmann
Copy link
Owner

Thank you!

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

Successfully merging this pull request may close these issues.

4 participants