<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Spurious -Wsign-conversion warning due to excessively clever glibc <sys/resource.h>"
   href="http://llvm.org/bugs/show_bug.cgi?id=20742">20742</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Spurious -Wsign-conversion warning due to excessively clever glibc <sys/resource.h>
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zackw@panix.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This test program ...

    #define _GNU_SOURCE
    #include <sys/resource.h>

    int spurious_sign_conversion_warning(int r, struct rlimit *l)
    {
        return setrlimit(r, l);
    }

... produces a spurious -Wsign-conversion warning when compiled against
recent GNU libc's headers:

    $ clang-3.5 -Wsign-conversion -c setrlimit.c 
    setrlimit.c:6:22: warning: implicit conversion changes signedness: 'int' to
          '__rlimit_resource_t' (aka 'enum __rlimit_resource')
[-Wsign-conversion]
        return setrlimit(r, l);
               ~~~~~~~~~ ^
    1 warning generated.

The problem is this construct in <sys/resource.h>:

    /* The X/Open standard defines that all the functions below must use
       `int' as the type for the first argument.  When we are compiling with
       GNU extensions we change this slightly to provide better error
       checking.  */
    #if defined __USE_GNU && !defined __cplusplus
    typedef enum __rlimit_resource __rlimit_resource_t;
    typedef enum __rusage_who __rusage_who_t;
    typedef enum __priority_which __priority_which_t;
    #else
    typedef int __rlimit_resource_t;
    typedef int __rusage_who_t;
    typedef int __priority_which_t;
    #endif

`enum __rlimit_resource` has no negative values and is therefore (I presume)
assigned an unsigned type, triggering the warning.

I don't think I should have to work around this in my code.  X/Open says the
type of `setrlimit`'s first argument is `int`, therefore `RLIM_*` constants
should be passed around in `int` variables.  Moreover, I don't see that there
*is* any workaround available to me in C that wouldn't harm portability to
other systems.  (A portable program can reasonably want to define `_GNU_SOURCE`
in order to take advantage of specific glibc features when available.)

I initially filed this as a bug with Debian's glibc (
<a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=758911">https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=758911</a> ) and was asked to
file an upstream clang bug inviting you to work with upstream glibc to resolve
this in a mutually satisfactory way.  I will also file an upstream glibc bug
report and add the URL here.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>