Use const static members for XPIDL constants instead of anonymous enums
Categories
(Core :: XPCOM, task, P5)
Tracking
()
People
(Reporter: tenthumbs, Unassigned)
References
Details
Attachments
(1 obsolete file)
Comment 1•21 years ago
|
||
Comment 2•21 years ago
|
||
Comment 4•21 years ago
|
||
Comment 5•21 years ago
|
||
Comment 6•21 years ago
|
||
Comment 7•21 years ago
|
||
Comment 12•20 years ago
|
||
Comment 13•20 years ago
|
||
Comment 14•15 years ago
|
||
Comment 15•15 years ago
|
||
Comment 16•3 years ago
|
||
The bug assignee didn't login in Bugzilla in the last 7 months.
:nika, could you have a look please?
For more information, please visit auto_nag documentation.
Comment 17•3 years ago
|
||
Before this change, all XPIDL constants were declared using an anonymous
enum
rather than using a static constant. This change makes the
generated code more consistent with what is done in languages like Rust.
Some small changes were needed due to signed/unsigned comparison
warnings which were previously silent.
Updated•3 years ago
|
Comment 18•3 years ago
|
||
This is easy enough to change, and seems worth doing. The compiler support issues are definitely not relevant 18 years later.
Comment 19•3 years ago
|
||
Comment 20•3 years ago
|
||
Backed out changeset 9cc08c2f20be (bug 239460) for causing build bustage.
Backout link: https://hg.mozilla.org/integration/autoland/rev/a2aa25965e8b7d0450fa21cf9635306e31745dd6
In file included from Unified_cpp_dom_media_autoplay0.cpp:2:
[task 2022-04-06T23:54:36.069Z] 23:54:36 INFO - /builds/worker/checkouts/gecko/dom/media/autoplay/AutoplayPolicy.cpp(112,7): error: call to 'GetInt' is ambiguous
[task 2022-04-06T23:54:36.069Z] 23:54:36 INFO - Preferences::GetInt("media.autoplay.default", nsIAutoplay::ALLOWED);
[task 2022-04-06T23:54:36.069Z] 23:54:36 INFO - ^~~~~~~~~~~~~~~~~~~
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - /builds/worker/workspace/obj-build/dist/include/mozilla/Preferences.h(140,19): note: candidate function
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - static nsresult GetInt(const char* aPrefName, int32_t* aResult,
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - ^
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - /builds/worker/workspace/obj-build/dist/include/mozilla/Preferences.h(166,18): note: candidate function
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - static int32_t GetInt(const char* aPrefName, int32_t aFallback = 0,
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - ^
[task 2022-04-06T23:54:36.071Z] 23:54:36 INFO - 1 error generated.
Comment 21•3 years ago
|
||
This reveals a fun new thing about MSVC/clang-cl which I hadn't realized until now: unlike other compilers, static integers like static constexpr int X = 0;
can coerce to a null T*
if their constant value happens to be 0
in these compilers, making the call above which got me backed out ambiguous. I can't think of any way to avoid this off the top of my head (it happens even if the expression isn't a literal 0
constant).
This isn't the case for any other compiler, and the fact that constants declared with enum { X = 0 };
don't have this property makes them startlingly less surprising to use here :-/
I think I'm going to abandon this patch for now, because I imagine there will be other failure cases like that, and I'm not sure if it's worth fixing them, as this change doesn't really have an immediate benefit other than generated code feeling slightly more modern & slightly better compiler warnings.
Updated•3 years ago
|
It may be worth trying const instead of constexpr?
Comment 23•3 years ago
|
||
It behaves the same way as constexpr
on msvc: https://godbolt.org/z/a8nGrePfh
Comment 24•3 years ago
|
||
(we don't really care about msvc anymore)
Comment 25•3 years ago
|
||
(In reply to Mike Hommey [:glandium] from comment #24)
(we don't really care about msvc anymore)
This is true, but clang-cl mimics this behaviour for compatibility with msvc, and we do use clang-cl.
Updated•2 years ago
|
Description
•