<html>
    <head>
      <base href="https://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 --- - If the contents of a nullptr_t are modified through type-punned union, conversions from that nullptr_t to bool don't behave the same as conversion from nullptr to bool" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23833&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=-RxfjlFHmfy801jMk3VbmFpcDrOwjRO8Fan06VHRaYo&s=9QP_rX4glBTp4yFBKAE-HK8i_pBY3GYq2kcEb92f6-8&e=">23833</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>If the contents of a nullptr_t are modified through type-punned union, conversions from that nullptr_t to bool don't behave the same as conversion from nullptr to bool
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.6
          </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>andrey.vul@gmail.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>According to [conv.ptr]/1, conversion from nullptr_t to bool is equivalent to
conversion from null pointer to bool.
The Standard does not specify whether conversion should happen from internal
state initialized at construction or from some pseudo-function `constexpr
nullpt_t::operator bool() const { return false; }`.

The test case uses a union to mutate the internals of a nullptr_t and then
checks if nullptr_t still converts correctly to bool, as if it were an
invariant of the type. In effect, the value of the nullptr_t need not be
accessed at cast since it's intended to decay to null pointer constant when
used as a prvalue.
But the value is accessed, causing the test case to fail.

### SOURCE: cat a.cc
#include <cassert>
union {
int x;
nullptr_t y;
} a = {37};

int main() {
assert(!static_cast<bool>(a.y));
}

## INVOCATION: clang++ -std=c++11 -v a.cc
clang version 3.6.1 (tags/RELEASE_361/final)
Target: powerpc64le-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/gsa/tlbgsa-h1/09/andreyv/clang/bin/clang-3.6" -cc1 -triple
powerpc64le-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
-main-file-name a.cc -mrelocation-model static -mthread-model posix
-mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
-fuse-init-array -target-cpu ppc64le -target-abi elfv2 -v -dwarf-column-info
-resource-dir /gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib/clang/3.6.1
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9/backward
-internal-isystem /usr/local/include -internal-isystem
/gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib/clang/3.6.1/include
-internal-externc-isystem /usr/include/powerpc64le-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-std=c++11 -fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 129 -mstackrealign -fno-signed-char -fobjc-runtime=gcc
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/a-98ec2a.o -x c++ a.cc
clang -cc1 version 3.6.1 based upon LLVM 3.6.1 default target
powerpc64le-unknown-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory
"/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9

/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9
 /usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9/backward
 /usr/local/include
 /gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib/clang/3.6.1/include
 /usr/include/powerpc64le-linux-gnu
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -m elf64lppc -dynamic-linker /lib64/ld64.so.2 -o
a.out
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu/crt1.o
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu/crti.o
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/crtbegin.o
-L/usr/lib/gcc/powerpc64le-linux-gnu/4.9
-L/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu
-L/lib/powerpc64le-linux-gnu -L/lib/../lib64 -L/usr/lib/powerpc64le-linux-gnu
-L/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../..
-L/gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib -L/lib -L/usr/lib /tmp/a-98ec2a.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/crtend.o
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu/crtn.o</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>