From: Remi Gacogne Date: Tue, 27 May 2025 12:49:52 +0000 (+0200) Subject: auth: Fix `ignoring attributes on template argument` warning in the GeoIP backend X-Git-Tag: dnsdist-2.0.0-beta1~61^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5506fd3e42a99909a04362a2e5f21b2441ecc364;p=thirdparty%2Fpdns.git auth: Fix `ignoring attributes on template argument` warning in the GeoIP backend g++ 15.1.1 reports: ``` geoipbackend.cc: In constructor 'GeoIPBackend::GeoIPBackend(const std::string&)': geoipbackend.cc:88:62: warning: ignoring attributes on template argument 'int (*)(DIR*)' [-Wignored-attributes] 88 | auto dirHandle = std::unique_ptr(opendir(getArg("dnssec-keydir").c_str()), closedir); ``` --- diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 137d932aae..7acf64d022 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -80,12 +80,28 @@ const static std::array GeoIP_MONTHS = {"jan", "feb", "mar", "apr", If the reference is external, we spoof up a CNAME, and good luck with that */ +struct DirPtrDeleter +{ + /* using a deleter instead of decltype(&closedir) has two big advantages: + - the deleter is included in the type and does not have to be passed + when creating a new object (easier to use, less memory usage, in theory + better inlining) + - we avoid the annoying "ignoring attributes on template argument ‘int (*)(DIR*)’" + warning from the compiler, which is there because closedir is tagged as __nonnull((1)) + */ + void operator()(DIR* dirPtr) const noexcept { + closedir(dirPtr); + } +}; + +using UniqueDirPtr = std::unique_ptr; + GeoIPBackend::GeoIPBackend(const string& suffix) { WriteLock writeLock(&s_state_lock); setArgPrefix("geoip" + suffix); if (!getArg("dnssec-keydir").empty()) { - auto dirHandle = std::unique_ptr(opendir(getArg("dnssec-keydir").c_str()), closedir); + auto dirHandle = UniqueDirPtr(opendir(getArg("dnssec-keydir").c_str())); if (!dirHandle) { throw PDNSException("dnssec-keydir " + getArg("dnssec-keydir") + " does not exist"); }