[cfe-dev] Spurious warning: unused parameter when used only in an expression error-ing out

Matthieu Monrocq matthieu.monrocq at gmail.com
Thu Jul 14 12:34:14 PDT 2011

Hello clang,

I made a strange discovery with a small helper function I wrote:

If one test the following (short) program:

struct A;

void sink(A,int);

void func(A const& a, int x, int y) {
   sink(a + x, y);

The following errors get emitted:

$ clang -fsyntax-only -Wunused-parameter unused_parameter.cpp
unused_parameter.cpp:15:11: error: invalid operands to binary expression
('const A' and 'int')
   sink(a + x, y);
        ~ ^ ~
unused_parameter.cpp:14:34: warning: unused parameter 'y'
void func(A const& a, int x, int y) {
1 warning and 1 error generated.

The first one is expected, however it seems its presence somehow
short-circuit the analysis of the whole expression and as a result we get
the spurious warning...

I feel that this is unwelcome, because it obfuscates the true error
(especially since I tend to compile with -Werror).

For reference, I use the following version of Clang:

$ clang --version
clang version 3.0 (trunk 132889)
Target: i686-pc-mingw32
Thread model: posix

I could not find any mention of such an issue with my Google-fu in the
cfe-dev archive, so please let me know if it already came up and it was
deemed unimportant.

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110714/908e5437/attachment.html>

More information about the cfe-dev mailing list