[cxx-abi-dev] Mangling literals
Jason Merrill
jason at redhat.com
Thu Jun 17 19:31:12 UTC 2010
On 05/20/2010 10:13 AM, Mike Herrick wrote:
> The first thought is to extend the unique numbering scheme currently used to identify string literals, but we're wondering if even that is necessary. We're not sure that you can write a test case that can distinguish two functions in overload resolution if they differ only in the contents of two string literals. For example, we need a mangling that differentiates between these:
>
> template<class T> auto f(T p1) -> decltype(p1 == "xyz") { return true; }
> template<class T> auto f(T p1) -> decltype(p1 == 0.0) { return false; }
> int main() {
> return !f("xyz");
> }
>
> but do we need to differentiate between these ambiguous cases:
>
> template<class T> auto f(T p1) -> decltype(p1 == "xyz") { return true; }
> template<class T> auto f(T p1) -> decltype(p1 == "abc") { return false; }
> template<class T> auto f(T p1) -> decltype(p1 == "x") { return false; }
> int main() {
> return !f("xyz");
> }
No, I'm pretty sure those are all functionally equivalent. I'm not
thinking of any way the content of a string literal can affect the type
of an expression, though it can participate in a constant-expression
through sizeof, i.e.
template<class T> auto f(T p1)-> T (*)[sizeof "a" - 3]
In which case we either need to collapse the sizeof or mangle the length
as well as the type. But then, I guess we already need to collapse the
sizeof in constant expression context.
So yes, I think your proposal should work.
Jason
More information about the cxx-abi-dev
mailing list