[LLVMbugs] [Bug 21917] Error in std::pair default constructor when elements are not default-constructible

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jul 18 01:59:16 PDT 2015


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

Louis Dionne <ldionne.2 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |ldionne.2 at gmail.com
         Resolution|WORKSFORME                  |---

--- Comment #2 from Louis Dionne <ldionne.2 at gmail.com> ---
The following code triggers a hard error:

-----------------------------------------------------
#include <utility>


struct NoDefault { NoDefault() = delete; };

template <typename T, typename = decltype(std::pair<T, T>{})>
void f(int) { }

template <typename T>
void f(long) { }

int main() {
    f<NoDefault>(1);
}
-----------------------------------------------------

Instead, one would expect that the first `f` SFINAEs out because
`std::pair<NoDefault, NoDefault>` is not default constructible.
Instead, `std::pair` always provide a default-constructor, but it
is ill-formed when `T` is not default constructible.

This causes code like 

    std::is_default_constructible<std::pair<NoDefault, NoDefault>>::value

to trigger a hard error instead of returning `false`.

Live example: http://melpon.org/wandbox/permlink/A0d3lFEeEXEs0BzT

-- 
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/20150718/1e0cf8e1/attachment.html>


More information about the llvm-bugs mailing list