<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:eric@efcs.ca" title="Eric Fiselier <eric@efcs.ca>"> <span class="fn">Eric Fiselier</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Unexpected compile time error with vector<bool>"
   href="https://llvm.org/bugs/show_bug.cgi?id=30357">bug 30357</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>eric@efcs.ca
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Unexpected compile time error with vector<bool>"
   href="https://llvm.org/bugs/show_bug.cgi?id=30357#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Unexpected compile time error with vector<bool>"
   href="https://llvm.org/bugs/show_bug.cgi?id=30357">bug 30357</a>
              from <span class="vcard"><a class="email" href="mailto:eric@efcs.ca" title="Eric Fiselier <eric@efcs.ca>"> <span class="fn">Eric Fiselier</span></a>
</span></b>
        <pre>First, this isn't actually a bug in libc++. There is no requirement that
vector<bool, MyAlloc>::reference and vector<bool, OtherAlloc>::reference be
compatible.

Additionally MSVC only accepts this code because `alloc` violates the Allocator
requirements [allocator.requirements]. Specifically it fails the requirement
that `alloc::rebind<T>::other::rebind<alloc::value_type>::other` is the same
type as `alloc`. This causes MSVC to accept your example because
`alloc::rebind<T>::other` is the same as `std::allocator<T>`. If you define
`alloc` as follows then MSVC will also reject your example:

```
template <class T> struct alloc : std::allocator<T> {
  template <class U> struct rebind { using other = alloc<U>; };
};
std::vector<bool> v1(10, false);
std::vector<bool, alloc<bool> >::reference r1 = v1[0];
```

GCC still accepts the above example, but not for any good reason.

GCC additionally allows C1::reference and C2::reference to be compatible even
when the pointer types differ. Meaning the reference type stores a raw pointer
and not a fancy pointer. AFAIK this breaks using the reference type across
segment boundaries.


So in summary it would be possible to make `C1::reference` and `C2::reference`
compatible whenever `C1::pointer` and `C2::pointer` are the same type. However
this seems unwise. IMHO attempting to use `C1::reference` and `C2::reference`
interchangeably is a bug, and libc++ is correct to reject this code. Therefore
attempting to support this behavior is just likely to cause/hide more bugs.</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>