From: Mike Hommey <glandium@debian.org>
Date: Wed, 14 Apr 2010 08:59:59 +0200
Subject: Do build time detection of 2-bytes wchar_t and char16_t support

https://bugzilla.mozilla.org/show_bug.cgi?id=559278
Closes: #577677
---
 xpcom/base/nscore.h                   |   22 ++++++++++++++++++++++
 xpcom/glue/nsStringAPI.h              |    1 +
 xpcom/string/public/nsLiteralString.h |    1 +
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/xpcom/base/nscore.h b/xpcom/base/nscore.h
index 927257f..20f607c 100644
--- a/xpcom/base/nscore.h
+++ b/xpcom/base/nscore.h
@@ -399,6 +399,28 @@ typedef PRUint32 nsrefcnt;
   #define HAVE_CPP_2BYTE_WCHAR_T
 #endif
 
+#ifdef __GNUC__
+/* char16_t is only available in gcc 4.4+ with experimental c++0x support
+ * (-std=c++0x or -std=gnu++0x) */
+#if defined(HAVE_CPP_CHAR16_T) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4) || !defined(__GXX_EXPERIMENTAL_CXX0X__))
+#warning libxul SDK was configured with char16_t support, but now building without
+#undef HAVE_CPP_CHAR16_T
+#elif ! defined(HAVE_CPP_CHAR16_T) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) && defined(__GXX_EXPERIMENTAL_CXX0X__)
+#warning libxul SDK was configured without char16_t support, but now building with
+#define HAVE_CPP_CHAR16_T
+#endif
+
+/* When gcc is not given -fshort-wchar, wchar_t is not 2-bytes wide */
+#if defined(HAVE_CPP_2BYTE_WCHAR_T) && (__SIZEOF_WCHAR_T__ != 2)
+#warning libxul SDK was configured with 2-byte wchar_t, but now building without
+#undef HAVE_CPP_2BYTE_WCHAR_T
+#elif ! defined(HAVE_CPP_2BYTE_WCHAR_T) && (__SIZEOF_WCHAR_T__ == 2)
+#warning libxul SDK was configured without 2-byte wchar_t, but now building with
+#define HAVE_CPP_2BYTE_WCHAR_T
+#endif
+
+#endif
+
 #ifndef __PRUNICHAR__
 #define __PRUNICHAR__
   /* For now, don't use wchar_t on Unix because it breaks the Netscape
diff --git a/xpcom/glue/nsStringAPI.h b/xpcom/glue/nsStringAPI.h
index 19ca533..a35ff78 100644
--- a/xpcom/glue/nsStringAPI.h
+++ b/xpcom/glue/nsStringAPI.h
@@ -1063,6 +1063,7 @@ private:
   #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
   typedef nsDependentString nsLiteralString;
 #else
+  #warning Using conversions for literal strings. Please consider using 2-bytes wchar_t or char16_t instead
   #define NS_LL(s)                                s
   #define NS_MULTILINE_LITERAL_STRING(s)          NS_ConvertASCIItoUTF16(s, PRUint32(sizeof(s)-1))
   #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(s, PRUint32(sizeof(s)-1))
diff --git a/xpcom/string/public/nsLiteralString.h b/xpcom/string/public/nsLiteralString.h
index 7808f24..2cf1f7b 100644
--- a/xpcom/string/public/nsLiteralString.h
+++ b/xpcom/string/public/nsLiteralString.h
@@ -91,6 +91,7 @@ literal_string( const nsACString::char_type* aPtr, PRUint32 aLength )
   #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
   typedef nsDependentString nsLiteralString;
 #else
+  #warning Using conversions for literal strings. Please consider using 2-bytes wchar_t or char16_t instead
   #define NS_LL(s)                                s
   #define NS_MULTILINE_LITERAL_STRING(s)          NS_ConvertASCIItoUTF16(s, PRUint32(sizeof(s)-1))
   #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(s, PRUint32(sizeof(s)-1))
