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

            Bug ID: 71675
           Summary: __atomic_compare_exchange_n returns wrong type for
                    typed enum
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: js at alien8 dot de
  Target Milestone: ---

Consider the following code:

enum class foo : unsigned char {
    FOO, BAR
};

foo v;

bool bar(foo old_v, foo new_v)
{
    return __atomic_compare_exchange_n(&v, &old_v, new_v, true,
                                       __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}

This fails to compile with 

% g++ -std=c++14 -c problem.cpp
reader.cpp: In function ‘bool bar(foo, foo)’:
reader.cpp:10:99: error: cannot convert ‘foo’ to ‘bool’ in return
     return __atomic_compare_exchange_n(&v, &old_v, new_v, true,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);

According to the manual __atomic_compare_exchange_n returns a bool, so this
error is bogus. The expected behavior is for __atomic_compare_exchange_n to
return a bool in the first place.

Manually casting the result of __atomic_compare_exchange_n to bool generates
the expected result.

The issue appears with gcc 5.3.1 20160406 (Red Hat 5.3.1-6) on Fedora 23 x86_64
and also with gcc 6.1 (tested using https://gcc.godbolt.org/)

Reply via email to