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

            Bug ID: 78078
           Summary: error on ATOMIC_VAR_INIT with aggregate initializer
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

This is the subject of C11 DR 485
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm#dr_485).  The
ATOMIC_VAR_INIT macro is intended to be used to initialize objects of atomic
types, including structs.  Unfortunately, the C specification suggests that the
macro accepts just one argument, making it unsuitable to initialize structs
with more than one member.  The test case below shows the problem.  As
indicated in the Committee Discussion section of the DR (and soon in the
Suggested Technical Corrigendum), the macro should be defined to take a
variable number of arguments so that code like in the test case below can be
correctly handled.

$ cat b.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall
-Wextra -Wpedantic b.c
#include <stdatomic.h>

struct S { int a, b; };

_Atomic struct S s = ATOMIC_VAR_INIT ({ 1, 2 });
b.c:5:47: error: macro "ATOMIC_VAR_INIT" passed 2 arguments, but takes just 1
 _Atomic struct S s = ATOMIC_VAR_INIT ({ 1, 2 });
                                               ^
b.c:5:22: error: ‘ATOMIC_VAR_INIT’ undeclared here (not in a function); did you
mean ‘ATOMIC_VAR_INIT’?
 _Atomic struct S s = ATOMIC_VAR_INIT ({ 1, 2 });
                      ^~~~~~~~~~~~~~~
                      ATOMIC_VAR_INIT

Reply via email to