From 2fd178de49b10c6120271af094dab9476145a37a Mon Sep 17 00:00:00 2001
From: Alberto Massari <amassari@apache.org>
Date: Tue, 4 Aug 2009 08:55:01 +0000
Subject: [PATCH] Add an autoconf test to verify if the compiler supports the
 matching operator delete (XERCESC-1380)

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@800703 13f79535-47bb-0310-9956-ffa450edef68
---
 configure.ac                                  | 29 +++++++++++++++++--
 .../util/Xerces_autoconf_config.hpp.in        |  2 ++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index a5c544d0d..a0c8fdf86 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,7 +55,8 @@ AC_MSG_RESULT($xerces_cv_rpath)
 
 # Checks for programs.
 AC_PROG_CXX
-AC_PROG_CC
+# Use the C++ compiler for the compile tests
+AC_LANG(C++)
 # used by "make check"
 AC_PROG_SED
 #it would be nice to also check for PERL...
@@ -255,10 +256,10 @@ AC_COMPILE_IFELSE(  [AC_LANG_PROGRAM([[#include <windows.h>
                                      [[DeleteFileW(file);]])],
                     [
                       xerces_cv_type_xmlch=wchar_t
-                   	  AC_MSG_RESULT([yes])
+                      AC_MSG_RESULT([yes])
                       AC_DEFINE_UNQUOTED([XERCES_INCLUDE_WCHAR_H], 1, [Define to have Xerces_autoconf_config.hpp include wchar.h])
                     ],
-	                [
+                    [
                       xerces_cv_type_xmlch=$xerces_cv_type_u16bit_int
                       AC_MSG_RESULT([no])
                     ]
@@ -266,6 +267,28 @@ AC_COMPILE_IFELSE(  [AC_LANG_PROGRAM([[#include <windows.h>
 
 AC_DEFINE_UNQUOTED([XERCES_XMLCH_T], [$xerces_cv_type_xmlch], [Define to the 16 bit type used to represent Xerces UTF-16 characters])
 
+AC_MSG_CHECKING([whether the compiler chokes on a placement operator delete])
+AC_COMPILE_IFELSE(  [AC_LANG_PROGRAM([[#include <stdlib.h>
+                                        
+                                        class XMemory
+                                        {
+                                        public :
+                                            void* operator new(size_t s) { return 0; }
+                                            void* operator new(size_t s, void* ptr) { return 0; }
+                                            void operator delete(void* p) {}
+                                            void operator delete(void* p, void* ptr) {}
+                                        };]],
+                                     [[ ]])],
+                    [
+                      AC_MSG_RESULT([no])
+                    ],
+                    [
+                      AC_MSG_RESULT([yes])
+                      AC_DEFINE_UNQUOTED([XERCES_NO_MATCHING_DELETE_OPERATOR], 1, [Define to have XMemory.hpp avoid declaring a matching operator delete for the placement operator new])
+                    ]
+                 )
+
+
 AS_IF([test x$ac_cv_type_size_t = xyes],
 	AC_DEFINE([XERCES_SIZE_T], [size_t], [Define as the appropriate size_t type]),
 	AC_DEFINE([XERCES_SIZE_T], [long], [Define as the appropriate size_t type]))
diff --git a/src/xercesc/util/Xerces_autoconf_config.hpp.in b/src/xercesc/util/Xerces_autoconf_config.hpp.in
index 43d93dbc2..7aa60813d 100644
--- a/src/xercesc/util/Xerces_autoconf_config.hpp.in
+++ b/src/xercesc/util/Xerces_autoconf_config.hpp.in
@@ -75,6 +75,8 @@
 #undef XERCES_PLATFORM_EXPORT
 #undef XERCES_PLATFORM_IMPORT
 
+#undef XERCES_NO_MATCHING_DELETE_OPERATOR
+
 // ---------------------------------------------------------------------------
 //  Include standard headers, if available, that we may rely on below.
 // ---------------------------------------------------------------------------
-- 
GitLab