diff options
| author | 2024-04-12 02:03:34 -0700 | |
|---|---|---|
| committer | 2024-04-15 23:46:28 +0000 | |
| commit | f257588ba1da87d5591fbc2356bd7392ef9299ea (patch) | |
| tree | df54ed373aadb2affece823529bc05c1792358b0 /compiler/optimizing/code_generator.h | |
| parent | 855f1680b05cd9a7b4775bb682882025dccef90d (diff) | |
Fix ExperimentalFlags operator== ambiguity
After switching to C++20, ExperimentalFlags doesn't compile:
art/runtime/runtime.h:809:42: error: use of overloaded operator '!=' is ambiguous (with operand types 'ExperimentalFlags' and 'art::ExperimentalFlags::(unnamed enum at art/runtime/experimental_flags.h:29:3)')
809 | return (experimental_flags_ & flags) != ExperimentalFlags::kNone;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~
art/runtime/experimental_flags.h:60:18: note: candidate function
60 | constexpr bool operator==(const ExperimentalFlags& b) const {
| ^
art/runtime/runtime.h:809:42: note: built-in candidate operator!=(enum art::ExperimentalFlags::(unnamed at art/runtime/experimental_flags.h:29:3), enum art::ExperimentalFlags::(unnamed at art/runtime/experimental_flags.h:29:3))
809 | return (experimental_flags_ & flags) != ExperimentalFlags::kNone;
| ^
There are two ways to compile ExperimentalFlags != unnamed-enum in
C++20:
* Convert the LHS ExperimentalFlags to unnamed-enum using the
user-declared conversion operator, then call the built-in
operator!=(unnamed-enum, unnamed-enum) function.
* Starting with C++20: convert unnamed-enum to ExperimentalFlags and
call the user-declared
operator==(ExperimentalFlags, ExperimentalFlags), negating the
result.
C++20 adds the ability for operator== to be called using != syntax, but
the ambiguity exists even in C++17 if this line:
return (experimental_flags_ & flags) != ExperimentalFlags::kNone;
is changed to:
return !((experimental_flags_ & flags) == ExperimentalFlags::kNone);
Removing the implicit ExperimentalFlags to unnamed-enum conversion
seems to be a sufficient fix, but this code can be simplified a lot
while only losing the operator bool, so do that instead.
Bug: 311052584
Test: remove cpp_std override and build Android
Test: atest art_standalone_cmdline_tests
Change-Id: I16e29705294c850118aec41d423cfbb02222b629
Diffstat (limited to 'compiler/optimizing/code_generator.h')
0 files changed, 0 insertions, 0 deletions