Jeremad
Jeremad

Reputation: 920

clang W flag order

I have noticed a funny behavior with clang (I use 3.6.0), and I have not found any reference about it in the documentation or anywhere else. 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:

main.cpp:2:9: warning: unused variable 'a' [-Wunused-variable]
    int a;
1 warning generated.

Now, let's try clang++ -Werror -Wno-error=unused-variable -Wall -W main.cpp

main.cpp:2:9: error: unused variable 'a' [-Werror,-Wunused-variable]
    int a;
1 error generated.

Have I missed something? Is it expected? For that matters, gcc compiles both lines.

Upvotes: 15

Views: 1398

Answers (1)

Jeremad
Jeremad

Reputation: 920

Here is what I was answered:

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.

Which I'm perfectly fine with. It just should be written somewhere (I may have missed it!)

Upvotes: 2

Related Questions