Bug 17809

Summary: Overload String::operator[] for integer types other than unsigned
Product: WebKit Reporter: Mark Mentovai <mark>
Component: WebKit Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Trivial CC: ap, darin, mjs
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.5   
Attachments:
Description Flags
Use 0U instead of 0 darin: review-

Description Mark Mentovai 2008-03-12 14:33:37 PDT
I've found that using operator[ to subscript a String in EditorCommand.cpp fails, the compiler giving the following error:

.../WebKit/WebCore/editing/EditorCommand.cpp: In function ‘bool WebCore::executeFormatBlock(WebCore::Frame*, WebCore::Event*, WebCore::EditorCommandSource, const WebCore::String&)’:
.../WebKit/WebCore/editing/EditorCommand.cpp:387: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
.../WebKit/WebCore/platform/text/PlatformString.h:72: note: candidate 1: UChar WebCore::String::operator[](unsigned int) const
.../WebKit/WebCore/editing/EditorCommand.cpp:387: note: candidate 2: operator[](NSString*, int) <built-in>

To resolve the ambiguity, I've used 0U instead of 0 to subscript the String in question.
Comment 1 Mark Mentovai 2008-03-12 14:35:25 PDT
Created attachment 19714 [details]
Use 0U instead of 0
Comment 2 Eric Seidel (no email) 2008-03-12 15:11:18 PDT
Ick.  I hope there is some other way to avoid this error.
Comment 3 Darin Adler 2008-03-13 09:44:18 PDT
Comment on attachment 19714 [details]
Use 0U instead of 0

This should only be an issue in Objective-C++ files. The ambiguity comes from the operator NSString*() overload.

Why are you seeing this ambiguity in a .cpp file? Are you trying to compile this file as ObjC++?
Comment 4 Darin Adler 2008-03-13 09:45:40 PDT
Comment on attachment 19714 [details]
Use 0U instead of 0

I'm going to mark this as review-.

The real problem is that this file is being compiled with __OBJC__ defined -- you need to figure out why.
Comment 5 Darin Adler 2008-03-13 09:47:34 PDT
Aside from the specific issues in this .cpp file, we can eliminate this ambiguity in ObjC++ files by overloading the String [] operator for integer types other than unsigned. But once we overload for any type other than unsigned, we'll need overloads for all the integer types we want to allow.

Doing that overload would be nice for ObjC++ files -- should not be relevant for this file, though.
Comment 6 Mark Mentovai 2008-03-13 11:38:07 PDT
Good catch, this file somehow got flipped to sourcecode.cpp.objcpp in my project.  I've got a few other filetype things that I've verified do exist in the trunk WebCore.xcodeproj, I'll file separately for those, leaving this bug to be repurposed per comment 5 if desired.
Comment 7 Mark Mentovai 2008-03-13 13:09:07 PDT
Filetype cleanup mentioned in comment 6 is bug 17833.
Comment 8 Mark Mentovai 2008-03-14 12:11:29 PDT
I found other uses of 0U to disambiguate between the two choices for operator[] in platform/graphics/mac/IconMac.mm and platform/mac/KeyEvent.mm.