[cxx-abi-dev] need mangling for string literals and lifetime-extended temporaries used in static constexpr member initializers and for string literals in constexpr functions

Richard Smith richardsmith at google.com
Fri May 24 05:23:19 UTC 2013


So... this problem was not really new in C++11. In C++98 it can be
witnessed for an inline function such as:

inline const char *get() {
  static const char *str = "foo";
  return str;
}

And for lifetime-extended temporaries:

inline const int *get() {
  static const int &n = 0;
  return &n;
}

In the latter case, both GCC and Clang have manglings for the
lifetime-extended temporary (although they both give it internal linkage),
following the pattern for GV manglings. They are:

Clang mangling:
  <special-name> ::= GR <object name>
This doesn't work, because a single object can lifetime extend multiple
entities (Clang does not model that situation correctly at the moment).

GCC mangling:
  <special-name> ::= GR <object name> <index>
... where <index> is the index of the lifetime-extended temporary *within
the TU*.

I suggest we adopt the GCC model for these cases, but specify how to count
the <index> within the object.

On Thu, May 23, 2013 at 9:56 PM, Richard Smith <richardsmith at google.com>wrote:

> Consider:
>
> // tu1
> struct A { static constexpr const char *p = "foo"; };
> const char *q = A::p;
> // tu2
> struct A { static constexpr const char *p = "foo"; };
> const char *r = A::p;
>
> We are required to ensure that q == r, but gcc, clang, and EDG all fail to
> do so. Therefore we presumably need to give the string literal a mangled
> name. Likewise for string literals which appear within constexpr function
> bodies:
>
> // tu1
> constexpr const char *get() { return "bar"; }
> const char *a = get();
> // tu2
> constexpr const char *get() { return "bar"; }
> const char *b = get();
>
> ... and also for lifetime-extended temporaries:
>
> struct X { int n; };
> struct B { static constexpr X &&x = {0}; };
> X &y = B::x; // must be same X object in all TUs
>
> (Both Clang and g++ have a rejects-valid on this, but EDG accepts it.)
>
> ... and likewise for lifetime-extended arrays underlying
> std::initializer_list objects.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20130523/6ac3c3d7/attachment.html>


More information about the cxx-abi-dev mailing list