[cfe-users] warning/error issues
David Blaikie
dblaikie at gmail.com
Fri Oct 11 19:00:24 PDT 2013
On Fri, Oct 11, 2013 at 6:58 PM, Eric Levy <contact at ericlevy.name> wrote:
> I stand corrected on the -Werror/-Wall issue.
>
> With respect to unused parameters, I do have -Wall enabled, however, the
> documentation states I can override it on particular types of warnings
> using -Wno-error=foo (this part is definitely different from gcc), however,
> I have been unsuccessful in doing so.
>
I demonstrated that in my example:
$ clang++-tot unused.cpp -Wextra -Werror -Wno-error=unused-parameter
unused.cpp:2:17: warning: unused parameter 'i' [-Wunused-parameter]
void func(int i) {
^
1 warning generated.
demoting the unused-parameter warning back from an error to a warning,
worked for me. You do need to use the exact warning name, not a warning
group (eg: -Wno-error=unused or -Wno-error=all won't work).
>
> Eric Levy
>
>
>
> On 10/11/2013 09:49 PM, David Blaikie wrote:
>
>>
>>
>>
>> On Fri, Oct 11, 2013 at 6:34 PM, Eric Levy <contact at ericlevy.name
>> <mailto:contact at ericlevy.name>**> wrote:
>>
>> Hello,
>>
>> I began to experiment with clang to build an existing C++ (Qt-based)
>> project. I wanted to make warnings into errors in order to ensure
>> that the code is solid. However, there are several issues:
>>
>> 1) Clang is said to be designed to have the same command-line
>> interface as gcc, but the options for warnings and errors are
>> different. The gcc command -Wall is -Werror in clang, and so on.
>>
>>
>> Actually Clang and GCC both have -Wall and -Werror and they do (roughly)
>> the same thing in each. -Wall is the "common likely-good warnings" and
>> -Werror is "whatever warnings are on, make them errors". The specific
>> set of things in -Wall differs somewhat between Clang and GCC since
>> there's no specific definition, but roughly speaking those flags do the
>> same thing.
>>
>>
>> 2) The user documentation states that specific warnings can be made
>> into errors or not errors by using the -Werror=foo and
>> -Wno-error=foo options. However, no list of accepted values for foo
>> is given.
>>
>>
>> This is a flaw in Clang's documentation - we basically don't document
>> our flags, so far as I know. You guess them, or you look at the
>> implementation, or try -Weverything (turns on all warnings) and see what
>> warnings fire and what their flags are called (we print the flag name by
>> default).
>>
>>
>> 3) Finally, gcc/clang both warn on unused variables and parameters.
>> This often undesired, especially in C++ where, due to polymorphism
>> some implementations of a method may not need certain parameters.
>>
>>
>> I don't believe Clang warns on unused parameters by default, if at all.
>> If it does so on virtual functions that's probably a bug to be fixed.
>>
>> When clang produces an error for unused parameters (-Werror
>> enabled), it reports the reason is -Wunused-parameter. However,
>> introducing -Wno-error=unused-parameter has no effect, despite
>> documentation to the contrary. The gcc-style -Wno-unused-parameter
>> is equally ineffective.
>>
>>
>> Could you show examples of this?
>>
>> -Wunused-parameter isn't under -Wall, so you must've passed it
>> explicitly I assume (or perhaps via -Wextra)?
>>
>> All these options seem to work quite well for me with Clang:
>>
>> $ clang++-tot unused.cpp -Wextra
>> unused.cpp:2:17: warning: unused parameter 'i' [-Wunused-parameter]
>> void func(int i) {
>> ^
>> 1 warning generated.
>> $ clang++-tot unused.cpp -Wextra -Werror
>> unused.cpp:2:17: error: unused parameter 'i' [-Werror,-Wunused-parameter]
>> void func(int i) {
>> ^
>> 1 error generated.
>> $ clang++-tot unused.cpp -Wextra -Werror -Wno-error=unused-parameter
>> unused.cpp:2:17: warning: unused parameter 'i' [-Wunused-parameter]
>> void func(int i) {
>> ^
>> 1 warning generated.
>> $ clang++-tot unused.cpp -Wextra -Werror -Wno-unused-parameter
>> $
>>
>> So too is replacing unused-parameter with simply unused, which, at
>> least according to gcc documentation, subsumes unused variables and
>> parameters alike.
>>
>> Whether these observations represent choice or oversight, I would
>> like to know how to make all warnings errors except for unused
>> variables and parameters.
>>
>> Thank you.
>>
>> Sincerely,
>> Eric Levy
>> ______________________________**___________________
>> cfe-users mailing list
>> cfe-users at cs.uiuc.edu <mailto:cfe-users at cs.uiuc.edu>
>> http://lists.cs.uiuc.edu/__**mailman/listinfo/cfe-users<http://lists.cs.uiuc.edu/__mailman/listinfo/cfe-users>
>> <http://lists.cs.uiuc.edu/**mailman/listinfo/cfe-users<http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users>
>> >
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20131011/07772625/attachment.html>
More information about the cfe-users
mailing list