]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Fix `ignoring attributes on template argument` warning in the GeoIP backend
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 27 May 2025 12:49:52 +0000 (14:49 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 27 May 2025 12:49:52 +0000 (14:49 +0200)
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<DIR, decltype(&closedir)>(opendir(getArg("dnssec-keydir").c_str()), closedir);
```

modules/geoipbackend/geoipbackend.cc

index 137d932aaecebc0991976148fb08e9ebdd59c292..7acf64d022bfdf92cf420b54174dbadac437390e 100644 (file)
@@ -80,12 +80,28 @@ const static std::array<string, 12> 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<DIR, DirPtrDeleter>;
+
 GeoIPBackend::GeoIPBackend(const string& suffix)
 {
   WriteLock writeLock(&s_state_lock);
   setArgPrefix("geoip" + suffix);
   if (!getArg("dnssec-keydir").empty()) {
-    auto dirHandle = std::unique_ptr<DIR, decltype(&closedir)>(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");
     }