WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
165477
Functions with a return type of ExceptionOr<String> cannot "return emptyString();"
https://bugs.webkit.org/show_bug.cgi?id=165477
Summary
Functions with a return type of ExceptionOr<String> cannot "return emptyStrin...
Jer Noble
Reported
2016-12-06 10:31:50 PST
Attempting to do so generates the following error: error: no viable conversion from returned value of type 'const WTF::String' to function return type 'ExceptionOr<WTF::String>' With the following notes: ExceptionOr.h:35:37: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const WTF::String' to 'const WebCore::ExceptionOr<WTF::String> &' for 1st argument ExceptionOr.h:37:5: note: candidate constructor not viable: no known conversion from 'const WTF::String' to 'WebCore::Exception &&' for 1st argument ExceptionOr.h:38:5: note: candidate constructor not viable: 1st argument ('const WTF::String') would lose const qualifier ExceptionOr.h:39:88: note: candidate template ignored: disabled by 'enable_if' [with OtherType = WTF::String]
Attachments
Add attachment
proposed patch, testcase, etc.
Darin Adler
Comment 1
2016-12-06 18:47:53 PST
The workaround is to write this: return String { emptyString() }; I’m not sure we need to fix this.
Darin Adler
Comment 2
2016-12-06 18:49:17 PST
Let me know if the workaround works or not. I’m sure we can come up with a way to make the syntax more elegant if this comes up a lot.
Darin Adler
Comment 3
2016-12-06 18:49:49 PST
I think this came up for me one time: in Internals::captionsStyleSheetOverride.
Jer Noble
Comment 4
2016-12-07 08:55:43 PST
(In reply to
comment #2
)
> Let me know if the workaround works or not.
It does!
> I’m sure we can come up with a way to make the syntax more elegant if this > comes up a lot.
I understand the motivation for not allowing "initialization-by-copy-constructor" by default, but I think this pattern may become more common. Enum values in WebIDL are turn into Strings in the bindings, and I've often defined "static const String& enumValue();" methods in tho bound classes to represent each enumerated value. A getter that can either return an enum value or throw an exception will likely hit this quirk. It may be worth it to make an exception (hah!) for ExceptionOr<String> or ExceptionOr<AtomicString>.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug