[cxx-abi-dev] string constant mangling

John McCall rjmccall at apple.com
Fri Jan 6 23:40:18 UTC 2012


On Jan 6, 2012, at 7:53 AM, Jason Merrill wrote:
> On 03/08/2011 04:12 PM, David Vandevoorde wrote:
>> On Mar 8, 2011, at 11:43 AM, Jason Merrill wrote:
>> 
>>> It occurs to me that now with constexpr, string constants can appear in a constant expression:
>>> 
>>> template<typename T>  constexpr T f(const T* p) { return p[0]; }
>>> template<int>  struct N { };
>>> template<typename T>  N<f((const T*)"1")>  g(T);
>>> template<typename T>  N<f((const T*)"2")>  g(T);
>>> 
>>> Here the two 'g's are different templates.
>> 
>> Ouch :-(  I guess another tweak is needed then.
> 
> So,
> 
> L <string type> <value string> E
> 
> where the string value is encoded in hex, omitting the terminal NUL?

This works for me.  Clarifications:
  - We don't need to distinguish "a" vs. u8"a" vs. R"a" because we're encoding
    the raw bytes as represented on the platform and because we're separately
    encoding the byte-length.
  - This implies platform endianness for multibyte encodings.
  - We should use lowercase hex to distinguish the terminal E.

> Maybe use an MD5 hash for strings longer than 16 bytes?

Probably a good idea.  Clarify as "more than 16 bytes of data,
excluding the implicit null on non-raw literals".

John.



More information about the cxx-abi-dev mailing list