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

--- Comment #9 from Bin Fan <bin.x.fan at oracle dot com> ---
I verified this bug is fixed in 5.1.0. However, it is only fixed in g++, so now
in 5.1.0, gcc and g++ reports different result:

-bash-4.1$ cat is_lock_free.c
#include <stdatomic.h>
#include <stdio.h>
#define N 10
typedef struct {
  char a[3];
} s3_t;
_Atomic s3_t array[N];
s3_t obj;

int main()
{
  int i;
  for (i=0;i<N;i++) {
      printf ("%x\t", &array[i]);
      printf("%d\n", atomic_is_lock_free (&array[i]));
  }

  for (i=0;i<N;i++) {
      atomic_store (&array[i], obj);
  }

  return 0;
}

gcc -latomic is_lock_free.c 
./a.out
20ff7   0
20ffa   1
20ffd   1
21000   1
21003   1
21006   0
21009   1
2100c   1
2100f   0
21012   1

-bash-4.1$ cat is_lock_free.cc 
#include <atomic>
#include <stdio.h>
using namespace std;
#define N 10
struct s3_t {
  char a[3];
};
atomic<s3_t> array[N];
s3_t obj;

int main()
{
  int i;
  for (i=0;i<N;i++) {
      printf ("%x\t", &array[i]);
      printf("%d\n", atomic_is_lock_free (&array[i]));
  }

  for (i=0;i<N;i++) {
      atomic_store (&array[i], obj);
  }

  return 0;
}

g++ -std=c++11 -latomic is_lock_free.cc
./a.out
21524   0
21527   0
2152a   0
2152d   0
21530   0
21533   0
21536   0
21539   0
2153c   0
2153f   0

Isn't the difference between C and C++ still a problem?

Reply via email to