Spurious warning: unused parameter when used only in an expression error-ing out

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’ [-Wunused-parameter]
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

We should probably not emit a -Wunused- warning in cases where a function doesn’t fully parse correctly. Please file a bug.

2011/7/14 Ted Kremenek <kremenek@apple.com>

We should probably not emit a -Wunused- warning in cases where a function doesn’t fully parse correctly. Please file a bug.

Done: http://llvm.org/bugs/show_bug.cgi?id=10371