Use a callable type for ScopedFILE in settings_writer.cc

Newer glibc have an attribute((nonnull(1))) on fclose. Attributes aren't
part of the language, so decltype(fclose) lose the attribute. It seems
this causes std::unique_ptr<FILE, decltype(fclose)> to trip
-Wignored-attributes in GCC.

This is a bit aggressive of a warning, but work around this with a
custom deleter, which makes the unique_ptr object smaller anyway.
(Though the compiler can, I hope, dissolve all of this anyway.)

Fixed: 642
Change-Id: I9a0206a8c5675f856e80c5266c90be42d66a5606
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62465
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
This commit is contained in:
David Benjamin
2023-08-17 15:06:32 -04:00
committed by Boringssl LUCI CQ
parent f896fbd7a9
commit e4f60679ca
+5 -2
View File
@@ -75,8 +75,11 @@ bool SettingsWriter::Commit() {
}
bssl::UniquePtr<uint8_t> free_settings(settings);
using ScopedFILE = std::unique_ptr<FILE, decltype(&fclose)>;
ScopedFILE file(fopen(path_.c_str(), "w"), fclose);
struct FileCloser {
void operator()(FILE *f) const { fclose(f); }
};
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
ScopedFILE file(fopen(path_.c_str(), "w"));
if (!file) {
return false;
}