Madison S
Madison S

Reputation: 225

Unexpected output from Clang

I've been testing out clang-llvm to see if it is worth it to mention to my school's IT department to add it to the machines we students program on. For all of our assignments, we are required to compile using g++ -Wall -W -pedantic-errors *.cpp, so I just converted the command to clang++ -Wall -W -pedantic-errors. I got some output that I wasn't expecting:

Attempting to compile...
In file included from test_library.cpp:6:
In file included from ./test_library.h:64:
In file included from ./library.h:167:
./library.hpp:20:23: warning: unused variable 'e' [-Wunused-variable]
    catch(Exception & e)
                      ^

Whereas the GCC compiler does not give an error about unused variables in the catch block. Is there anything I can do so that Clang does not freak out about unused variables in try/catch blocks while keeping the command similar to the g++ one?

Clang-LLVM(v2.7) GNU GCC(v4.4.4) Fedora 13

Upvotes: 1

Views: 1129

Answers (2)

Alex Emelianov
Alex Emelianov

Reputation: 1274

What's wrong with catching exception with "catch(Exception &)" if you are not using the variable? You compilers AND your code reviewers will be happier.

Upvotes: 3

zwol
zwol

Reputation: 140786

I kinda agree with Mike, but for getting-off-the-ground's sake, try this:

clang++ -Wall -W -pedantic-errors -Wno-unused-variable

I haven't used llvm much but I think the point of the [-Wunused-variable] in the diagnostic is to tell you that you can shut that warning up with -Wno-unused-variable.

Upvotes: 5

Related Questions