[Bug libstdc++/95606] [10/11 regression] <any> conflicts with std::is_constructible

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jun 10 09:37:29 GMT 2020


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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The testcase is:

#include <any>
#include <string>

template<typename>
class basic_json;

using json = basic_json<std::string>;

class json_ref
{
  public:
    template <typename T,
              bool = std::is_constructible<json, T>::value>
    json_ref(T &&){}
};

template<typename>
class basic_json
{
  public:
    basic_json(json_ref) {}
};

namespace std {

template<>
void swap<json>(json&, json&) noexcept {}

}

int main() {}


This fails when compiled with -std=gnu++17 or later.

Specializing std::swap like this is wrong (and in C++20 explicitly results in
undefined behaviour). Replacing it with a normal overload in the same namespace
as the type avoids the error.

Do you have an example that doesn't involve a bogus specialization in namespace
std?


More information about the Gcc-bugs mailing list