llvm / llvm-project

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

`-Wall` flag position should not matter #24750

Open llvmbot opened 9 years ago

llvmbot commented 9 years ago
Bugzilla Link 24376
Version 3.6
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@Weverything

Extended Description

Here is a small example

int main(){ 
    int a; 
    return 0; 
}

I compile it with

clang++ -Wall -W -Werror -Wno-error=unused-variable main.cpp

And I have the expected warning. Now If I compile with:

clang++ -W -Werror -Wno-error=unused-variable -Wall main.cpp

It triggers an error, so it seems like the position of Wall changes the behavior, which I think is not expected.

http://stackoverflow.com/questions/31855216/clang-w-flag-order

llvmbot commented 9 years ago

Indeed you're right guys. Would be nice if it was documented, though

Weverything commented 9 years ago

I think that the better title would be that -Wno-error is position dependent on the command line while -Werror is not. The important part is whether the diagnostic is an error or a warning. With the example:

int main() {
  int a;
  return 0;
}
$ clang main.cpp -Wunused-variable

This gives an unused variable warning.

$ clang main.cpp -Werror -Wunused-variable
$ clang main.cpp -Wunused-variable -Werror

Both of these give an unused variable error. -Werror does not change behavior based on position.

$ clang main.cpp -Werror -Wno-error=unused-variable -Wunused-variable
$ clang main.cpp -Werror -Wunused-variable -Wno-error=unused-variable

The first gives an error while the second gives an warning. This means that -Wno-error=* is position dependent. (GCC will issue warnings for both of these lines.)

-Werror does not interact or depend on the warnings on the command line. -Wno-error=warning does depend on its relative position to -Wwarning.

llvmbot commented 9 years ago

W options are processed left-to-right. Consider:

 clang++ -Wunused-variable -Wno-unused-variable main.cpp # no warning
 clang++ -Wno-unused-variable -Wunused-variable main.cpp # warning

The first line happens to give same as the default behavior for that warning, but it's immaterial. The point is that "last one wins"

So this a matter of opinion that -Wall should be interpreted first, when really it is just like any other -Wthing, but is shorthand for "all the things"

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-driver

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [24376](https://llvm.org/bz24376) | | Version | 3.6 | | OS | Linux | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor,@Weverything | ## Extended Description Here is a small example ```cpp int main(){ int a; return 0; } ``` I compile it with ``` clang++ -Wall -W -Werror -Wno-error=unused-variable main.cpp ``` And I have the expected warning. Now If I compile with: ``` clang++ -W -Werror -Wno-error=unused-variable -Wall main.cpp ``` It triggers an error, so it seems like the position of `Wall` changes the behavior, which I think is not expected. http://stackoverflow.com/questions/31855216/clang-w-flag-order