[llvm-bugs] [Bug 30357] Unexpected compile time error with vector<bool>

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Nov 13 20:56:08 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=30357

Eric Fiselier <eric at efcs.ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |eric at efcs.ca
         Resolution|---                         |INVALID

--- Comment #1 from Eric Fiselier <eric at efcs.ca> ---
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161114/3cfbbcfd/attachment.html>


More information about the llvm-bugs mailing list