[Bug libstdc++/101124] [12 Regression] pair<T*, int>(0, 0) was intended to be deprecated, but is rejected now

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jan 18 11:11:43 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101124

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Another example that now fails:

#include <utility>
struct X { } x;
std::pair<const X, void*> p(x, 0);

This selects the pair<T1,T2>::pair<U1,U2>(U1&&, U2&&) constructor, because x is
non-const and the pair<T1,T2>::first_type type is const. U2 gets deduced as
int, and int cannot convert to a pointer.

This code is just wrong and the standard says it should not compile, it should
be fixed to use p(x, nullptr).

p(std::as_const(x), 0) would also work, but is gross. Just use nullptr.


More information about the Gcc-bugs mailing list