Open Bug 304648 Opened 19 years ago Updated 2 years ago

Can use nsAString as concrete type

Categories

(Core :: XPCOM, defect, P3)

x86
Windows XP
defect

Tracking

()

People

(Reporter: Biesinger, Unassigned)

Details

The following code compiles:
    nsCAutoString asdf("asdf");
    nsACString foo = NS_LITERAL_CSTRING("foo") + asdf;

Should it?
No. I'm presuming from the nsCAutoString that this is the internal string API?
right. Note that just:
  nsACString foo;
does indeed fail to compile.
I'd think that the code at http://lxr.mozilla.org/seamonkey/source/xpcom/string/public/nsTAString.h#587 would deal with this (unless you're using one of those compilers, which I doubt)...
nope.  it is this constructor:
http://lxr.mozilla.org/seamonkey/source/xpcom/string/public/nsTAString.h#488
That constructor is used to support automatic promotion of a nsSubstringTuple, which does not inherit from nsAString, to a nsAString in XPCOM method calls.

There is no real harm in the code in comment #0, right?
probably not... but couldn't that conversion also be implemented using an:

  operator nsTAString_CharT();

on the substring tuple?
> probably not... but couldn't that conversion also be implemented using an:
> 
>   operator nsTAString_CharT();
> 
> on the substring tuple?

I tried that first, but it didn't seem to work out very well.  It might be worth playing around with it again, but I seem to recall that either the casting operator wasn't being invoked, or it was resulting in extra data copying.  It's been a while.  Feel free to experiment!
Priority: -- → P3
Component: String → XPCOM
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.