[llvm-bugs] [Bug 50219] New: Unable to use regular NULL as initializer for atomic function pointer in C

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 4 07:05:36 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50219

            Bug ID: 50219
           Summary: Unable to use regular NULL as initializer for atomic
                    function pointer in C
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: martin at martin.st
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

$ cat test-atomic.c 
typedef void (*fp)(void);
_Atomic fp ptr1 = ((void(*)(void))0);
_Atomic fp ptr2 = ((void*)0);
$ gcc -c test-atomic.c -Wall -Wextra
$ clang -c test-atomic.c
test-atomic.c:3:19: error: initializer element is not a compile-time constant
_Atomic fp ptr2 = ((void*)0);
                  ^~~~~~~~~~
1 error generated.


When initiailizing an _Atomic function pointer, which is a pointer to a
function, clang errors out when initializing it to the common NULL define
(which often expands to ((void*)0) in C). Using 0 cast to the right function
pointer type works.

GCC accepts the construct without warnings.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210504/284e1afa/attachment.html>


More information about the llvm-bugs mailing list