https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121574

--- Comment #9 from shyeyian <shyeyian at petalmail dot com> ---
If you aim to write strictly standard-conforming C++ code, please:
- Do not explicitly ignore `-Wexpose-global-module-tu-local` warnings.
  - This is similar to not ignoring `warning: ISO C++ forbids converting a
string constant to 'char*' [-Wwrite-strings]` (as this might be unsafe, and
that warning is meant for those porting or integrating a C header into a C++
project).
  - Also is similar to not ignoring `warning: ISO C++ forbids variable length
array` warnings when writing code like `int arr[n]` (as this is unstandard).
- Ensure **all of your code, including code in external headers** satisfy the
[module requirements](https://eel.is/c++draft/basic.link#18).
- Most third-party libraries (around 97%) are not yet modularized, according to
[arewemodulesyet](https://arewemodulesyet.org).
- Many third-party libraries are difficult to modularize with GCC, because they
indirectly reference TU-local (translation-unit local) entities.
- Same third-party libraries can easily be modularized in Clang or MSVC, since
these compilers allow exposing TU-local entities — though such behavior is
*not* strictly standard-compliant.
- For example,
  - Boost.Asio
    - Attempting to export `boost::asio::io_context`,
      - which calls `boost::asio::detail::socket_ops::network_to_host_long`,
      - which internally calls a TU-local system function `__uint32_t
_OSSwapInt32(__uint32_t)` on macOS,
      - which cannot be exported!
      - Therefore, exporting `boost::asio::io_context` is not allowed under
strict standard rules.
  - Eigen
    - Attempting to export `Eigen::Matrix`,
      - which has template argument `Eigen::Matrix<Scalar_, Rows_, Cols_>`, 
      - which internally calls `Rows_ == 1, 2 or 3` or `Rows_ ==
Eigen::Dynamic`.
      - which is a TU-local variable `const Eigen::Dynamic = -1`, 
      - which cannot be exported!
      - Thus, exporting `Eigen::Matrix` is not allowed under strict standard
rules.

---

If, on the other hand, you are comfortable packaging practical modular code of
third-party libraries:
- You may explicitly ignore `-Wexpose-global-module-tu-local` warnings.
- At your own risk, see [example](https://modules.godbolt.org/z/c9jPjPbq3).
- Ensure **your own `.cppm` files** satisfy the [module
requirements](https://eel.is/c++draft/basic.link#18), while **external
headers** are not necessarily required.
- Most third-party libraries (around 97%) are not yet modularized, according to
[arewemodulesyet](https://arewemodulesyet.org).
- Many third-party libraries can easily be modulized, if you want.
- For example,
  - Boost.Asio
    ```cpp
    module;
    #include <boost/asio.hpp>
    export module boost.asio;
    export namespace boost::asio {
        using io_context = boost::asio::io_context; // OK in Clang/MSVC,
warning in GCC, error in strict-standard mode.
    }
    ```

Thank you! :)

Reply via email to