https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90881

--- Comment #6 from Federico Kircheis <federico.kircheis at gmail dot com> ---
> With my patch, we wouldn't warn on this second testcase.  But clang++
> doesn't warn, either.

Yes, I just wanted to point out that giving warning in unevaluated contexts has
some benefits too.
I believe gcc is doing a better job than clang or msvc.

I actually thought about this bug, and would like to rephrase it.
It's not a false positive, it's an usability bug.



It's not problematic that gcc gives a warning, the text is
problematic/misleading.

It says "left operand of comma operator has no effect", and as I showed this is
wrong.

It should say "left operand of comma operator is not used" or something in that
direction, since the warning should be about unused variables
(`-Wunused-value`), and it would be correct.


As a programmer I can see more easily what gcc is trying to say, and I would be
less tempted to remove the unused variable because gcc did not told me it was
useless.


Now you might think, that this does not help me as programmer at all, since I
would like to write warning-free code, and I might be tempted to remove the
unused variable also in this situation.


Therefore, just add the hint (as actually documented), to cast the variable to
void!
Exactly as on would normally do for other unused variables.
I did not think about it, because I payed too much attention at the error text,
and not the cause of the warning.

This sample does compile, works as expected, and does not generate any warning.

----
#include <type_traits>

template <typename T, typename = void> struct status : std::false_type{};

template <typename T> struct status<T, decltype((void)T::member, void())> :
std::true_type {};

struct s1{int member;};
struct s2{int _member;};

int main(){
        static_assert(status<s1>::value, "has member");
        static_assert(!status<s2>::value, "has no member");
}
----

What do you think?

Reply via email to