[flang-commits] [flang] [flang][OpenMP] Silence unused-but-set-variable message (NFC) (PR #130979)
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Fri Mar 14 08:17:58 PDT 2025
Meinersbur wrote:
> Is it? I am reading `When casting to void to suppress warnings about unused variables (as an alternative to [[maybe_unused]]). Prefer C-style casts in this instance.` as saying `[[maybe_unused]]` is also OK.
That section is about that `(void)` is an exception to the ban of using C-style casts. It explains that there are two alternatives to do the same language in the C++, where `[[maybe_unused]]` is the other. The LLVM coding style choses the `(void)` alternative of the two as "it is preferred to write the code like". In fact, the example given is exactly the situation here: A variable only used in an `assert`.

How is this any ambigous?
> What is wrong with using this C++17 standard feature?
That the LLVM coding standard is preferring cast-to-void instead. It also does not allow exceptions even though it is a C++ standard feature.
Personally, what I think speaks against it is that it introduces yet another unused variable. If there are two unused variables in the same scope, they also need different names. When the type is non-trivial, it may involve runtime costs by e.g. calling a copy-ctor which is not guaranteed to be optimized away, including in debug builds.
https://github.com/llvm/llvm-project/pull/130979
More information about the flang-commits
mailing list