[LLVMdev] Correct use of StringRef and Twine
clattner at apple.com
Fri Jul 22 11:02:45 PDT 2011
On Jul 21, 2011, at 12:30 AM, David Blaikie wrote:
>> [diff attached]
> Updated diff with test fix. (since this broke a test (printing chars
> as numerical values, rather than characters) it's possible this change
> is a bad idea & it could break the product code itself. Though
> strangely I wasn't able to do character concatenation without my
> change, so I have a sneaking suspicion that while the test passed, it
> didn't actually expose this case to the common Twine use cases.
> Perhaps only explicitly invoking the Twine ctor would've got the
> char-as-number behavior previously)
The dangerous part of this is that characters are integers, so "foo" + 'x' is very likely to cause serious problems. This is the reason that the integer versions of the twine ctor are marked 'explicit'. I'm ok with the Twine class changes in this patch if the ctor is marked 'explicit'. You should also probably add a ctor for signed/unsigned char as well (which reuse the existing CharKind enum).
I'll respond to Triple specific issues in response to your previous email. Thanks for pushing this forward David!
More information about the llvm-dev