[llvm] [NFC] Fix dangling-else warning (PR #112817)
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 09:59:07 PDT 2024
jsji wrote:
> > Given that omit braces in such cases is part of LLVM's style guide
>
> Reference: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
>
> > I wonder whether it may be better to use `-Wno-dangling-else` when compiling gtest based code using GCC?
> > As Clang doesn't have this false positive, this warning will creep back in over time.
>
> Agree. But where is the else in this case? I assume it is inside the gtest macros being invoked in the if statement bodies - might be better to add fixes there?
The problem here is because these macros, eg: `EXPECT_TRUE` are expanded to a single line multi-statement code, which is indeed ambiguous after pre-processing. a simple example would be like: https://godbolt.org/z/4zjn56qrP
I don't think it is realistic to change gtest code for such warnings. So, either disable the warnings, or add braces.
https://github.com/llvm/llvm-project/pull/112817
More information about the llvm-commits
mailing list