summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-03-29 11:03:47 +0200
committerLuboš Luňák <l.lunak@suse.cz>2012-03-29 11:12:22 +0200
commit8aa60b51a9e48b33ba6f0cb27132c6a415de2358 (patch)
tree2ad80da5172c7843c4a62f5cf6d1c737e98545c8
parenta159dfbea39dd3470837e73bf2df4cd2a0f3e806 (diff)
(const) char[] (i.e. size unknown) cannot be used with O(U)String
msvc can't handle the necessary template overload (and maybe it's right, I'm not sure)
-rw-r--r--sal/inc/rtl/stringutils.hxx9
-rw-r--r--sal/qa/rtl/strings/test_ostring_stringliterals.cxx19
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx4
-rw-r--r--sw/source/filter/ww8/rtfexport.hxx4
4 files changed, 29 insertions, 7 deletions
diff --git a/sal/inc/rtl/stringutils.hxx b/sal/inc/rtl/stringutils.hxx
index 19c1bf460fb4..3ed36a758aaa 100644
--- a/sal/inc/rtl/stringutils.hxx
+++ b/sal/inc/rtl/stringutils.hxx
@@ -65,6 +65,12 @@ There are 2 cases:
cast to const char*. Additionally (non-const) char[N] needs to be handled, but with the reference
being const, it would also match const char[N], so another overload with a reference to non-const
and NonConstCharArrayDetector are used to ensure the function is called only with (non-const) char[N].
+Additionally, char[] and const char[] (i.e. size unknown) are rather tricky. Their usage with 'T&' would
+mean it would be 'char(&)[]', which seems to be invalid. But gcc and clang somehow manage when it is
+a template. while msvc complains about no conversion from char[] to char[1]. And the reference cannot
+be avoided, because 'const char[]' as argument type would match also 'const char[N]'
+So char[] and const char[] should always be used with their contents specified (which automatically
+turns them into char[N] or const char[N]), or char* and const char* should be used.
*/
struct Dummy {};
template< typename T1, typename T2 >
@@ -91,6 +97,8 @@ struct NonConstCharArrayDetector< char[ N ], T >
{
typedef T Type;
};
+#ifdef RTL_STRING_UNITTEST
+// never use, until all compilers handle this
template< typename T >
struct NonConstCharArrayDetector< char[], T >
{
@@ -101,6 +109,7 @@ struct NonConstCharArrayDetector< const char[], T >
{
typedef T Type;
};
+#endif
template< typename T1, typename T2 >
struct ConstCharArrayDetector
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index 0d5036aa2f11..d7e3cf5be7c4 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -66,6 +66,9 @@ private:
void testcall( const char str[] );
+ static const char bad5[];
+ static char bad6[];
+
CPPUNIT_TEST_SUITE(StringLiterals);
CPPUNIT_TEST(checkCtors);
CPPUNIT_TEST(checkUsage);
@@ -100,13 +103,20 @@ void test::ostring::StringLiterals::checkCtors()
const char* bad4[] = { "test1" };
CPPUNIT_ASSERT( !CONST_CTOR_USED( bad4[ 0 ] ));
testcall( good1 );
+#ifndef _MSC_VER
+ // this is actually not supposed to work (see discussion in stringutils.hxx),
+ // but gcc and clang somehow manage, so keep it used, just in case some other problem
+ // shows up somewhen in the future
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( bad5 )); // size is not known here
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( bad6 ));
+#endif
// This one is technically broken, since the first element is 6 characters test\0\0,
// but there does not appear a way to detect this by compile time (runtime will complain).
// RTL_CONSTASCII_USTRINGPARAM() has the same flaw.
- const char bad5[][ 6 ] = { "test", "test2" };
- CPPUNIT_ASSERT( CONST_CTOR_USED( bad5[ 0 ] ));
- CPPUNIT_ASSERT( CONST_CTOR_USED( bad5[ 1 ] ));
+ const char bad7[][ 6 ] = { "test", "test2" };
+ CPPUNIT_ASSERT( CONST_CTOR_USED( bad7[ 0 ] ));
+ CPPUNIT_ASSERT( CONST_CTOR_USED( bad7[ 1 ] ));
// Check that contents are correct and equal to the case when const char* ctor is used.
CPPUNIT_ASSERT( rtl::OString( (const char*)"" ) == rtl::OString( "" ));
@@ -128,6 +138,9 @@ void test::ostring::StringLiterals::checkCtors()
#endif
}
+const char test::ostring::StringLiterals::bad5[] = "test";
+char test::ostring::StringLiterals::bad6[] = "test";
+
void test::ostring::StringLiterals::testcall( const char str[] )
{
#ifndef _MSC_VER
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index dda8b81df9a4..00b8e18c9cf1 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -79,10 +79,10 @@ using rtl::OUStringBuffer;
using sw::mark::IMark;
-#if defined(UNX)
+#if defined(UNX22)
const sal_Char RtfExport::sNewLine = '\012';
#else
-const sal_Char RtfExport::sNewLine[] = "\015\012";
+const sal_Char* const RtfExport::sNewLine = "\015\012";
#endif
// the default text encoding for the export, if it doesn't fit unicode will
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
index 3759f318306d..9d395de0e209 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -155,10 +155,10 @@ public:
/// Destructor.
virtual ~RtfExport();
-#if defined(UNX)
+#if defined(UNX22)
static const sal_Char sNewLine; // \012 or \015
#else
- static const sal_Char sNewLine[]; // \015\012
+ static const sal_Char* const sNewLine; // \015\012
#endif
rtl_TextEncoding eDefaultEncoding;