groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] Help needed: C++11 language lawyer


From: G. Branden Robinson
Subject: [groff] Help needed: C++11 language lawyer
Date: Sun, 12 Nov 2017 10:31:13 -0500
User-agent: NeoMutt/20170113 (1.7.2)

Hi folks,

I'm working on https://savannah.gnu.org/bugs/index.php?52335 and I've
reached the limit of my knowledge of C++.

The problem is a compiler warning:

src/libs/libgroff/new.cpp:60:6: warning: the program should also define
'void operator delete(void*, long unsigned int)' [-Wsized-deallocation]
 void operator delete(void *p)

Background material:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3663.html

I have a patch that quiets the sized-deallocation warning, but the most
obvious solution (to me) causes a different warning.

diff --git a/src/libs/libgroff/new.cpp b/src/libs/libgroff/new.cpp
index 7a1a4730..dc2580f4 100644
--- a/src/libs/libgroff/new.cpp
+++ b/src/libs/libgroff/new.cpp
@@ -67,3 +67,22 @@ void operator delete(void *p)
     free(p);
 #endif /* COOKIE_BUG */
 }
+
+void operator delete(void *p,
+                    __attribute__((__unused__)) long unsigned int size)
+{
+  // It's ugly to duplicate the code from delete(void *) above, but if
+  // we don't, g++ 6.3 can't figure out we're calling through it to
+  // free().
+  //
+  // In function 'void operator delete(void*, long unsigned int)':
+  //   warning: deleting 'void*' is undefined [-Wdelete-incomplete]
+  //delete p;
+#ifdef COOKIE_BUG
+  if (p)
+    free((void *)((char *)p - 8));
+#else
+  if (p)
+    free(p);
+#endif /* COOKIE_BUG */
+}

The options as I see it are:

A. Live with the existing warning.
B. Live with the new warning.
C. Duplicate the code.
D. Find the correct and idiomatic solution.

My preference would be for D but I ain't got it, and I need help.

My next preference, and my intention if no one can help, is to do C,
shown above.  It's not _much_ duplicated code[1], and we're actually
really close to having a warning-free groff build[2] under GCC 6.3 even
with "-Wall -Wextra".  I'd like to get us the rest of the way there so
we don't get into the habit of ignoring them.

Thanks in advance for any assistance!

[1] Especially if someone happens to know that the malloc cookie bug no
    longer exists on any supported groff target, in which case we can
    slim down this entire file to near-triviality.  If that was a Linux
    libc4 problem, for example, that's probably the case.

[2] gnulib's vasprintf() is throwing us a warning about comparison
    operands differing in signedness.  At some point I'll send them a
    bug about it.

-- 
Regards,
Branden

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]