Skip to content

Build warnings with clang 6 #2466

Closed
Closed
@rikardfalkeborn

Description

@rikardfalkeborn

I did this

Built curl with clang 6.0.0.

$ ./buildconf
$ ./configure --enable-debug --enable-warnings --enable-werror CC=clang
$ make check
$ clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

I expected the following

Successful build. Instead, I got this:

unit1309.c:91:24: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]
    nodes[i].payload = CURLX_INTEGER_TO_POINTER_CAST(payload);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../lib/warnless.h:32:26: note: expanded from macro 'CURLX_INTEGER_TO_POINTER_CAST'                                                                                
  ((void *)((char *)NULL + (i)))
            ~~~~~~~~~~~~ ^
unit1309.c:125:34: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]              
      nodes[i * 3 + j].payload = CURLX_INTEGER_TO_POINTER_CAST(payload);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../lib/warnless.h:32:26: note: expanded from macro 'CURLX_INTEGER_TO_POINTER_CAST'                                                                                
  ((void *)((char *)NULL + (i)))

Looks like this warning has been improved/changed in clang 6. From http://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html#improvements-to-clang-s-diagnostics

-Wnull-pointer-arithmetic now warns about performing pointer arithmetic on a null pointer. Such pointer arithmetic has an undefined behavior if the offset is nonzero. It also now warns about arithmetic on a null pointer treated as a cast from integer to pointer (GNU extension).

curl/libcurl version

$ git rev-parse HEAD
dd03e8c281582af454fabfb4a666a5b232d518aa
$ ./src/curl -V 
curl 7.60.0-DEV (x86_64-pc-linux-gnu) libcurl/7.60.0-DEV OpenSSL/1.1.0h zlib/1.2.11 brotli/1.0.2 libidn2/2.0.4 libpsl/0.20.1 (+libidn2/2.0.4) nghttp2/1.31.0 librtmp/2.3
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS Debug TrackMemory IDN IPv6 Largefile NTLM NTLM_WB SSL libz brotli TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

operating system

Linux (Arch Linux)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions