[cfe-users] warning/error issues

David Blaikie dblaikie at gmail.com
Sat Oct 12 18:07:00 PDT 2013


This is just a matter of ordering:

$ clang++-tot unused.cpp -Werror -Wno-error=unused-parameter
-Wunused-parameter
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.

Which differs from GCC, which warns in both cases. This is arguably (not
sure if the Clang behavior is intentional) a bug in Clang. Feel free to
file it at llvm.org/bugs - in the mean time you can workaround it by
putting the -Werror related flags last.


On Fri, Oct 11, 2013 at 7:13 PM, Eric Levy <contact at ericlevy.name> wrote:

> Evidently my build is not behaving the same way, as demonstrated below.
>  Version information is also shown.
>
>
> % clang -c -m64 -pipe -std=c++0x -Werror -Wno-error=unused-parameter -g
> -fPIC -Wall -W -D_REENTRANT -DQT_XMLPATTERNS_LIB -DQT_CONCURRENT_LIB
> -DQT_NETWORK_LIB -DQT_XML_LIB -DQT_CORE_LIB -I/opt/qt-5.0.0-linux64-**
> ubuntu1204-gcc/mkspecs/linux-**g++-64 -I../src -I/opt/qt-5.0.0-linux64-**ubuntu1204-gcc/include
> -I/opt/qt-5.0.0-linux64-**ubuntu1204-gcc/include/**QtXmlPatterns
> -I/opt/qt-5.0.0-linux64-**ubuntu1204-gcc/include/**QtConcurrent
> -I/opt/qt-5.0.0-linux64-**ubuntu1204-gcc/include/**QtNetwork
> -I/opt/qt-5.0.0-linux64-**ubuntu1204-gcc/include/QtXml
> -I/opt/qt-5.0.0-linux64-**ubuntu1204-gcc/include/QtCore -I. -I. -o
> ../obj/QDavResource.o ../src/QDavResource.cpp
> ../src/QDavResource.cpp:12:60: error: unused parameter 'propList'
>       [-Werror,-Wunused-parameter]
> void QDavResource::setPropertyList(**const QDavPropertyList* propList) {
>                                                            ^
> 1 error generated.
>
>
> % clang -v
> Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM
> 3.0)
> Target: x86_64-pc-linux-gnu
> Thread model: posix
>
>
>
> On 10/11/2013 10:00 PM, David Blaikie wrote:
>
>>
>>
>>
>> On Fri, Oct 11, 2013 at 6:58 PM, Eric Levy <contact at ericlevy.name
>> <mailto: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>
>>         <mailto: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>
>>         <mailto: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>
>> >
>>              <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/20131012/05cf8233/attachment.html>


More information about the cfe-users mailing list