Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


On Sun, 2011-02-27 at 04:27 -0500, Kevin Hunter wrote:
Is that + operator expected to work with an O*String and a single character?

From analysis with Sébastien Le Ray, it looks like what's happening is 
that the b OString is converted to sal_Char *, and the compiler uses 
int( '\n' ) (=10) for the + operator.  So, the pointer of "Gobble 
Wobble" is moved to "ble" before the += operator takes over.


Yeah, looks that way.

Changing the suspect line to

a += b + "\n";

Indeed, a OString can be constructed from a "const sal_Char*", which is
just a "const char*", so OString+"\n", gets... 

OString operator+(const OString &, const OString&), and the
OString(const sal_Char*) ctor is used to generate the 2nd OString from
the "\n". In the other case, the OString(sal_Char) ctor is an explicit
one (i.e. a += b + OString('\n') should do the right thing), so no
OString is generated for '\n', so the other direction is tried, and
OString has a operator const sal_Char*().

This is the kind of monstrosity that has the suggestion for "explicit"
to be allowed for conversion operators in C++0x.

Three possibilities I guess, 

1) remove the "explicit", but I'm sure its there due to some other
horribly implicit conversion horror
2) add a operator+(sal_Char), either one that "just works", or one that
raises an error at compile time.
3) remove the const sal_Char* conversion operator (I'm tempted towards
this one)

C.


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.