llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.84k stars 11.01k forks source link

-Wextra-semi does not imply -Wextra-semi-stmt #41401

Open llvmbot opened 5 years ago

llvmbot commented 5 years ago
Bugzilla Link 42056
Version 7.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

Clang does not warn to remove the empty expression statement with the warning flag [-Wextra-semi].

For the following example, Clang does not warn to remove the empty expression statement with the warning flag [-Wextra-semi]. $ cat s.c int main() { int a = 0; ; return 0; }

$ clang --version clang version 7.0.0 (tags/RELEASE_700/final) Target: x86_64-unknown-linux-gnu Thread model: posix

$ clang -Wextra-semi s.c No warning generated.

Under the same workstation: $ clang-8.0 --Wextra-semi-stmt s.c s.c:4:5: warning: empty expression statement has no effect; remove unnecessary ';' to silence this warning [-Wextra-semi-stmt] ; ^ 1 warning generated.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 5 years ago

Yes, -Wextra-semi and -Wextra-semi-stmt are two different warnings that fire on different cases. -Wextra-semi catches extra semicolons outside of a function, where they are an error in some language modes (but Clang accepts them as an extension). -Wextra-semi-stmt catches empty statements in compound-statements, which is valid in all language modes, but usually unintentional (though harmless).

Having different warning flags for different situations is intentional, but for historical reasons -Wextra-semi catches just the declaration case. We could reconsider that (maybe rename -Wextra-semi to -Wextra-semi-decl and make -Wextra-semi cover both -Wextra-semi-decl and -Wextra-semi-stmt).