 |
|
|
|
Actions
|
|
[ Date Prev][ Date Next][ Thread Prev][ Thread Next][ Date Index][ Thread Index]
Re: [cxx-abi-dev] Scope encoding of string literals in default arguments questions
- To: cxx-abi-dev@xxxxxxxxxxxxxxxx
- Subject: Re: [cxx-abi-dev] Scope encoding of string literals in default arguments questions
- From: scott douglass <sdouglass@xxxxxxx>
- Date: Mon, 11 Nov 2002 10:18:50 +0000
Mark Mitchell wrote:
--On Friday, November 01, 2002 11:47:59 AM +0000 scott douglass
<sdouglass@xxxxxxx> wrote:
Hi,
I have some questions about the scope encoding of string literals in
inline functions. Consider,
bool g(const char*);
inline const char* f1(const char* p = "world"); // _ZZ2f1Es ?
inline const char* f1(const char* p) {
g(p);
g("hello"); // _ZZ2f1Es_0 ?
g("world"); // _ZZ2f1Es ?
}
I think that the only consistent thing to do is to move the default
argument into the callers; that is where it will be emitted.
But, doesn't the expression 'f1()' have to supply the same pointer for 'p' even in different translation units? As far as I can tell the standard doesn't address this directly.
I'll also suggest some minor clarifications to the wording in 5.1.6:
"Note that this assumes that the same string literal occurring twice in
a given function in fact represents a single entity, i.e. has a unique
address."
would be better as
"Note that this means that the same string literal occurring twice in a
given inline function in fact represents a single entity, i.e. has a
unique address. It also means that string literals in inline functions
do not "tail-share", i.e. the string literals "abc" and "bc" are
completely distinct in inline functions."
Why?
I think I see what you mean. As long as the compiler counts the orignial string literals:
void h(const char *);
inline void k() {
h("bc"); // _ZZ1kEs
h("abc"); // _ZZ1kEs_0
}
A compiler could make the references to '_ZZ1kEs_0 + 1' and '_ZZ1kEs_0'. It doesn't even need to emit '_ZZ1kEs' because anyone referring to '_ZZ1kEs' will also emit it.
|
|