<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 --- - Problem with tenary operator and errno: although condition is true it evaluates the else part"
   href="http://llvm.org/bugs/show_bug.cgi?id=18644">18644</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Problem with tenary operator and errno: although condition is true it evaluates the else part
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>christian@2ndquadrant.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>Hi,

while working on a patch for PostgreSQL I noticed that a error hint was not
displayed. The hint has been set via a ternary operator and a comparison of
errno:

            ereport(FATAL,
                    (errmsg("could not map anonymous shared memory: %m"),
                     (errno == ENOMEM) ?
                     errhint("This error usually means that PostgreSQL's
request "
                             "for a shared memory segment exceeded available
memory "
                             "or swap space. To reduce the request size
(currently "
                             "%zu bytes), reduce PostgreSQL's shared memory
usage, "
                             "perhaps by reducing shared_buffers or "
                             "max_connections.",
                             *size) : 0));

In this case (checked with GDB) is errno == ENOMEM, but the hint wont appear.
The same code works fine with GCC.

clang version used:

clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-pc-linux-gnu
Thread model: posix

gcc version used:

gcc (Gentoo 4.7.3-r1 p1.4, pie-0.5.5) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I wasn't able to create a small test case, but I uploaded my current working
tree so you can check it out:

<a href="http://www.defunced.de/postgres-working-tree.tgz">http://www.defunced.de/postgres-working-tree.tgz</a>

The compiler flags I used are in both cases (gcc and clang):

-O0 -g -W -Wall -ansi -pedantic -pipe -std=c99 -Wall -Wmissing-prototypes
-Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv
-fexcess-precision=standard

I configured with this statement for clang:

CFLAGS="-O0 -g -W -Wall -ansi -pedantic -pipe -std=c99" CC=/usr/bin/clang
./configure --prefix=/home/ckruse/dev/postgres/

and with this for GCC:

CFLAGS="-O0 -g -W -Wall -ansi -pedantic -pipe -std=c99" ./configure
--prefix=/home/ckruse/dev/postgres/

Best regards,

-- 
 Christian Kruse               <a href="http://www.2ndQuadrant.com/">http://www.2ndQuadrant.com/</a>
 PostgreSQL Development, 24x7 Support, Training & Services</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>