Last Comment Bug 764104 - Compilation fails if C++ keyword used in WebIDL enum.
: Compilation fails if C++ keyword used in WebIDL enum.
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: unspecified
: x86 Mac OS X
: -- normal (vote)
: mozilla16
Assigned To: Boris Zbarsky [:bz] (still a bit busy)
:
: Andrew Overholt [:overholt]
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-12 12:31 PDT by William Chen [:wchen]
Modified: 2012-06-16 06:51 PDT (History)
4 users (show)
bzbarsky: in‑testsuite?
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Avoid collisions with C++ reserved words by using initial-caps for WebIDL enum values. (3.79 KB, patch)
2012-06-12 19:00 PDT, Boris Zbarsky [:bz] (still a bit busy)
peterv: review+
Details | Diff | Splinter Review

Description William Chen [:wchen] 2012-06-12 12:31:20 PDT
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).
Comment 1 Boris Zbarsky [:bz] (still a bit busy) 2012-06-12 12:43:46 PDT
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").
Comment 2 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-06-12 12:55:32 PDT
I vote for upper case.
Comment 3 Boris Zbarsky [:bz] (still a bit busy) 2012-06-12 19:00:02 PDT
Created attachment 632504 [details] [diff] [review]
Avoid collisions with C++ reserved words by using initial-caps for WebIDL enum values.
Comment 4 Boris Zbarsky [:bz] (still a bit busy) 2012-06-15 14:55:01 PDT
https://hg.mozilla.org/integration/mozilla-inbound/rev/0fd65c8f53c8
Comment 5 Ryan VanderMeulen [:RyanVM] 2012-06-16 06:51:18 PDT
https://hg.mozilla.org/mozilla-central/rev/0fd65c8f53c8

Note You need to log in before you can comment on or make changes to this bug.