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

            Bug ID: 90881
           Summary: -Wunused-value false positive with
           Product: gcc
           Version: 9.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.kircheis at gmail dot com
  Target Milestone: ---

Hello,

consider

----
#include <type_traits>

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

template <typename T> struct status<T, decltype(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");
}
----

When compiling with `-Wall` (or `-Wunused-value`), g++ generates following
warning:


--
bug.cpp: In instantiation of ‘struct status<s1>’:
bug.cpp:11:26:   required from here
bug.cpp:5:58: warning: left operand of comma operator has no effect
[-Wunused-value]
 template <typename T> struct status<T, decltype(T::member, void())> :
std::true_type {};
                                                 ~~~~~~~~~^~~~~~~~
bug.cpp:5:58: warning: left operand of comma operator has no effect
[-Wunused-value]
--


The warning is incorrect, as removing the left operand changes the behaviour of
the program, thus it has effect:

----
#include <type_traits>

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

template <typename T> struct status<T, decltype(void())> : std::true_type {};
// ! removed left operand

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");
}
----

Does not compile:

--
bug.cpp: In function ‘int main()’:
bug.cpp:12:16: error: static assertion failed: has no member
  static_assert(!status<s2>::value, "has no member");
--

because `status` does not detect anymore if the member-variable `member` is
present or not.

Reply via email to