Skip to content

#defining defined() in macros is undefined #25

Description

@bentley

Clang-5.0.1 on OpenBSD complains when compiling dns.c:

cc -std=gnu99 -Wall -Wextra -O2 -g -fstack-protector -O2 -pipe  -DDNS_DEBUG -DDNS_MAIN  -o dns dns.c 
dns.c:383:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
#if HAVE___ATOMIC_FETCH_ADD && __GCC_ATOMIC_LONG_LOCK_FREE == 2
    ^
dns.c:375:34: note: expanded from macro 'HAVE___ATOMIC_FETCH_ADD'
#define HAVE___ATOMIC_FETCH_ADD (defined __ATOMIC_RELAXED)
                                 ^
dns.c:392:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
#if HAVE___ATOMIC_FETCH_SUB && __GCC_ATOMIC_LONG_LOCK_FREE == 2
    ^
dns.c:379:33: note: expanded from macro 'HAVE___ATOMIC_FETCH_SUB'
#define HAVE___ATOMIC_FETCH_SUB HAVE___ATOMIC_FETCH_ADD
                                ^
dns.c:375:34: note: expanded from macro 'HAVE___ATOMIC_FETCH_ADD'
#define HAVE___ATOMIC_FETCH_ADD (defined __ATOMIC_RELAXED)
                                 ^
dns.c:788:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
#if DNS_HAVE_SOCKADDR_UN
    ^
dns.c:782:31: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                              ^
dns.c:788:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
dns.c:782:51: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                                                  ^
dns.c:843:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
#if DNS_HAVE_SOCKADDR_UN
    ^
dns.c:782:31: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                              ^
dns.c:843:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
dns.c:782:51: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                                                  ^
dns.c:849:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
#if DNS_HAVE_SOCKADDR_UN
    ^
dns.c:782:31: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                              ^
dns.c:849:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
dns.c:782:51: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                                                  ^
dns.c:909:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
#if DNS_HAVE_SOCKADDR_UN
    ^
dns.c:782:31: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                              ^
dns.c:909:5: warning: macro expansion producing 'defined' has undefined behavior
      [-Wexpansion-to-defined]
dns.c:782:51: note: expanded from macro 'DNS_HAVE_SOCKADDR_UN'
#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
                                                  ^
dns.c:6134:5: warning: macro expansion producing 'defined' has undefined
      behavior [-Wexpansion-to-defined]
#if HAVE_SOCK_CLOEXEC
    ^
dns.c:6118:28: note: expanded from macro 'HAVE_SOCK_CLOEXEC'
#define HAVE_SOCK_CLOEXEC (defined SOCK_CLOEXEC)
                           ^
dns.c:6137:5: warning: macro expansion producing 'defined' has undefined
      behavior [-Wexpansion-to-defined]
#if HAVE_SOCK_NONBLOCK
    ^
dns.c:6122:29: note: expanded from macro 'HAVE_SOCK_NONBLOCK'
#define HAVE_SOCK_NONBLOCK (defined SOCK_NONBLOCK)
                            ^
dns.c:6143:25: warning: macro expansion producing 'defined' has undefined
      behavior [-Wexpansion-to-defined]
#if defined F_SETFD && !HAVE_SOCK_CLOEXEC
                        ^
dns.c:6118:28: note: expanded from macro 'HAVE_SOCK_CLOEXEC'
#define HAVE_SOCK_CLOEXEC (defined SOCK_CLOEXEC)
                           ^
dns.c:6148:28: warning: macro expansion producing 'defined' has undefined
      behavior [-Wexpansion-to-defined]
#if defined O_NONBLOCK && !HAVE_SOCK_NONBLOCK
                           ^
dns.c:6122:29: note: expanded from macro 'HAVE_SOCK_NONBLOCK'
#define HAVE_SOCK_NONBLOCK (defined SOCK_NONBLOCK)
                            ^
dns.c:6206:26: warning: macro expansion producing 'defined' has undefined
      behavior [-Wexpansion-to-defined]
#if (defined F_SETFD && !HAVE_SOCK_CLOEXEC) || (defined O_NONBLOCK && !H...
                         ^
dns.c:6118:28: note: expanded from macro 'HAVE_SOCK_CLOEXEC'
#define HAVE_SOCK_CLOEXEC (defined SOCK_CLOEXEC)
                           ^
dns.c:6206:72: warning: macro expansion producing 'defined' has undefined
      behavior [-Wexpansion-to-defined]
  ...F_SETFD && !HAVE_SOCK_CLOEXEC) || (defined O_NONBLOCK && !HAVE_SOCK_NONB...
                                                               ^
dns.c:6122:29: note: expanded from macro 'HAVE_SOCK_NONBLOCK'
#define HAVE_SOCK_NONBLOCK (defined SOCK_NONBLOCK)
                            ^
16 warnings generated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions