Compilation fails if C++ keyword used in WebIDL enum.

RESOLVED FIXED in mozilla16

Status

()

Core
DOM
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: wchen, Assigned: bz)

Tracking

unspecified
mozilla16
x86
Mac OS X
Points:
---
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

5 years ago
WebIDL enum containing a C++ keyword will generate C++ a enum that contain the keyword, causing compilation to fail.

Example:

enum NotificationPermission {
  "default",
  "denied",
  "granted"
};

taken from (http://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html#api) will generate:

enum valuelist {
  default,
  denied,
  granted
};

The enum above will fail to compile due to the "default" keyword (at least in clang).
Yeah, this is a bit of a PITA.  

One option is to upcase the first character of each enum value.  So we would have:

  enum valuelist {
    Default,
    Denied,
    Granted
  };

Another is to add more special cases to getEnumValueName (there's already a special case for "", but we could add one for "default").
I vote for upper case.
Created attachment 632504 [details] [diff] [review]
Avoid collisions with C++ reserved words by using initial-caps for WebIDL enum values.
Attachment #632504 - Flags: review?(peterv)
Assignee: nobody → bzbarsky
Whiteboard: [need review]
Attachment #632504 - Flags: review?(peterv) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/0fd65c8f53c8
Flags: in-testsuite?
Whiteboard: [need review]
Target Milestone: --- → mozilla16
https://hg.mozilla.org/mozilla-central/rev/0fd65c8f53c8
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.