[fidl][cpp] Don't use ToUnderlying when converting enums

When the new C++ bindings is used in Chromium we found that
HLCPP/natural enum conversion breaks when an enum-less library is
included in front of the library of interest. The reason is that we have
multiple overloads of `fidl::ToUnderlying`. There is one overload for
HLCPP strict enums, and separate overloads defined for natural strict &
flexble enums. Due to [1], a templated class that uses ToUnderlying can
only use ToUnderlying overloads that were already included before it.
Thus sometimes the natural strict & flexible overloads aren't visible to
the compiler.

In user code, people can call `fidl::ToUnderlying` and all the necessary
overloads are already included. However, inside FIDL library code such
as `lib/fidl/cpp/hlcpp_conversion.h`, not all `fidl::ToUnderlying` are
defined at the point when that header is included.

The most straightforward solution is to not use `fidl::ToUnderlying` in
FIDL runtime libraries.

[1]: https://en.cppreference.com/w/cpp/language/dependent_name

Change-Id: I8c1058cb4b1eae5e5d3b9f38a769c19aad0c855a
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/800049
Reviewed-by: Ian McKellar <ianloic@google.com>
Commit-Queue: Yifei Teng <yifeit@google.com>
API-Review: Ian McKellar <ianloic@google.com>
54 files changed
tree: 2ff1511918b0846e138de04760b6ff87ca108c8b
  1. boards/
  2. build/
  3. bundles/
  4. docs/
  5. examples/
  6. products/
  7. scripts/
  8. sdk/
  9. src/
  10. third_party/
  11. tools/
  12. zircon/
  13. .clang-format
  14. .clang-tidy
  15. .editorconfig
  16. .git-blame-ignore-revs
  17. .gitattributes
  18. .gitignore
  19. .gitmodules
  20. .gn
  21. .style.yapf
  22. analysis_options.yaml
  23. AUTHORS
  24. BUILD.gn
  25. CODE_OF_CONDUCT.md
  26. CONTRIBUTING.md
  27. fuchsia.code-workspace
  28. LICENSE
  29. OWNERS
  30. PATENTS
  31. pyrightconfig.json
  32. README.md
  33. rustfmt.toml
README.md

Fuchsia

What is Fuchsia?

Fuchsia is an open source, general purpose operating system supporting modern 64-bit Intel and ARM processors.

We expect everyone interacting with our project to respect our code of conduct.

Read more about Fuchsia's principles.

How can I build and run Fuchsia?

See Getting Started.

Where can I learn more about Fuchsia?

See fuchsia.dev.