[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 06:29:56 UTC 2013


On Thu, May 23, 2013 at 10:41 PM, John McCall <rjmccall at apple.com> wrote:

> On May 23, 2013, at 10:23 PM, Richard Smith <richardsmith at google.com>
> wrote:
> > 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;
> > }
>
> How is this different from the following?
>
>   inline const char *get_nostatic() { return "foo"; }
>
> or
>
>   inline const char *get_separate() {
>     const char *temp = "foo";
>     static const char *str = tmp;
>     return str;
>   }
>
> Please find or add something in the standard which will allow us to
> not export a symbol for every string literal(*) that happens to be used
> in a function with weak linkage.


Finding failed. In addition to the implications of the ODR, we have this:

[dcl.fct.spec]p4: "A string literal in the body of an extern inline
function is the same object in different translation units."

On the adding front, perhaps the simplest way to avoid generating such
extra symbols (at least, in most cases) would be to specify that a string
literal expression may produce the address of a different (static storage
duration) object each time it is evaluated.  However, even if we allow
that, I don't think it's reasonable for an unchanging static storage
duration pointer or reference to point at different objects depending on
who is asking.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20130523/4ac754b3/attachment-0001.html>


More information about the cxx-abi-dev mailing list