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

wrap cfile's fclose() to avoid warning on latest glibc #1592

Merged
merged 3 commits into from
Sep 5, 2023

Conversation

spoonincode
Copy link
Member

latest glibc adds a __nonnull attribute on fclose() which ends up causing a bunch of warnings,

libraries/libfc/include/fc/io/cfile.hpp:22:65: warning: ignoring attributes on template argument ‘int (*)(FILE*)’ [-Wignored-attributes]
   22 |    using unique_file = std::unique_ptr<FILE, decltype( &fclose )>;

Not really sure the best way of fixing this. Simply wrapping the call like this gets rid of the warning.

@@ -19,7 +19,11 @@
namespace fc {

namespace detail {
using unique_file = std::unique_ptr<FILE, decltype( &fclose )>;
static void close_file(FILE* f) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe inline would be better here than static.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yep

@greg7mdp
Copy link
Contributor

greg7mdp commented Sep 5, 2023

Why not just replace the unique_file definition with:
using unique_file = std::unique_ptr<FILE, decltype( [](FILE *f) noexcept { (void)fclose(f); } )>;
and not provide &fclose when constructing a unique_file?

@spoonincode
Copy link
Member Author

Why not just replace the unique_file definition with: using unique_file = std::unique_ptr<FILE, decltype( [](FILE *f) noexcept { (void)fclose(f); } )>; and not provide &fclose when constructing a unique_file?

That caused a different warning for me (that to be honest I didn't investigate)

libraries/libfc/include/fc/io/cfile.hpp:31:7: warning: ‘fc::cfile’ has a field ‘fc::detail::unique_file fc::cfile::_file’ whose type has internal linkage [-Wsubobject-linkage]
   31 | class cfile {

@@ -19,7 +19,11 @@
namespace fc {

namespace detail {
using unique_file = std::unique_ptr<FILE, decltype( &fclose )>;
inline void close_file(FILE* f) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inline void close_file(FILE* f) {
inline void close_file(FILE* f) noexcept {

@spoonincode spoonincode merged commit 409eb59 into main Sep 5, 2023
@spoonincode spoonincode deleted the cfile_warn_be_gone branch September 5, 2023 18:39
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