Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang W flag order

Tags:

c++

clang++

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.

like image 392
Jeremad Avatar asked Aug 06 '15 12:08

Jeremad


People also ask

Does Clang define __ GNUC __?

(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.

What is Clang ++ command?

clang is a C, C++, and Objective-C compiler which encompasses preprocessing, parsing, optimization, code generation, assembly, and linking.

Is Clang better than G ++?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

What is Clang command line?

Introduction. The Clang Compiler is an open-source compiler for the C family of programming languages, aiming to be the best in class implementation of these languages. Clang builds on the LLVM optimizer and code generator, allowing it to provide high-quality optimization and code generation support for many targets.


1 Answers

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!)

like image 96
Jeremad Avatar answered Sep 18 '22 05:09

Jeremad