From b47f1f95f352fe9c1b4299f065cff39d222610bf Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Wed, 30 Nov 2005 16:31:19 +0000
Subject: [PATCH] added wxSUPPRESS_GCC_PRIVATE_DTOR_WARNING macro

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36308 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/function.tex | 31 +++++++++++++++++++++++++++++++
 include/wx/defs.h          | 13 +++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index b96a451336..0c2607b303 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -243,6 +243,7 @@ the corresponding topic.
 \helpref{wxStringTokenize}{wxstringtokenize}\\
 \helpref{wxStripMenuCodes}{wxstripmenucodes}\\
 \helpref{wxStrlen}{wxstrlen}\\
+\helpref{wxSUPPRESS\_GCC\_PRIVATE\_DTOR\_WARNING}{wxsuppress\_gcc\_private\_dtor\_warning}\\
 \helpref{wxSysErrorCode}{wxsyserrorcode}\\
 \helpref{wxSysErrorMsg}{wxsyserrormsg}\\
 \helpref{wxT}{wxt}\\
@@ -3177,6 +3178,36 @@ as a keyboard shortkey in Windows and Motif) and $\backslash$t (tab in Windows).
 <wx/utils.h>
 
 
+\membersection{wxSUPPRESS\_GCC\_PRIVATE\_DTOR\_WARNING}{wxsuppress\_gcc\_private\_dtor\_warning}\\
+
+\func{}{wxSUPPRESS\_GCC\_PRIVATE\_DTOR\_WARNING}{\param{}{name}}
+
+GNU C++ compiler gives a warning for any class whose destructor is private
+unless it has a friend. This warning may sometimes be useful but it doesn't
+make sense for reference counted class which always delete themselves (hence
+destructor should be private) but don't necessarily have any friends, so this
+macro is provided to disable the warning in such case. The \arg{name} parameter
+should be the name of the class but is only used to construct a unique friend
+class name internally. Example of using the macro:
+
+\begin{verbatim}
+    class RefCounted
+    {
+    public:
+        RefCounted() { m_nRef = 1; }
+        void IncRef() { m_nRef++ ; }
+        void DecRef() { if ( !--m_nRef ) delete this; }
+
+    private:
+        ~RefCounted() { }
+
+        wxSUPPRESS_GCC_PRIVATE_DTOR(RefCounted)
+    };
+\end{verbatim}
+
+Notice that there should be no semicolon after this macro.
+
+
 \membersection{wxULL}\label{wxull}
 
 \func{wxLongLong\_t}{wxULL}{\param{}{number}}
diff --git a/include/wx/defs.h b/include/wx/defs.h
index c9d7f22c3e..0e292d26e8 100644
--- a/include/wx/defs.h
+++ b/include/wx/defs.h
@@ -88,6 +88,19 @@
 #   pragma warn -inl                /*  Functions containing reserved words and certain constructs are not expanded inline */
 #endif /*  __BORLANDC__ */
 
+/*
+   g++ gives a warning when a class has private dtor if it has no friends but
+   this is a perfectly valid situation for a ref-counted class which destroys
+   itself when its ref count drops to 0, so provide a macro to suppress this
+   warning
+ */
+#ifdef __GNUG__
+#   define wxSUPPRESS_GCC_PRIVATE_DTOR_WARNING(name) \
+        friend class wxDummyFriendFor ## name;
+#else /* !g++ */
+#   define wxSUPPRESS_GCC_PRIVATE_DTOR_WARNING(name)
+#endif
+
 /*  ---------------------------------------------------------------------------- */
 /*  wxWidgets version and compatibility defines */
 /*  ---------------------------------------------------------------------------- */
-- 
2.45.2

