mardi 1 mars 2016

What is the portable way to forward-declare classes in an inline namespace in libc++?

The following code doesn't compile only when I specify -stdlib=libc++ to clang++:

namespace std {
  class mutex;
}

void f(std::mutex &x);

#include <mutex>

void f(std::mutex &x) { }

note: candidate found by name lookup is 'std::__1::mutex'

I understand what is ::__1 there,

but to my eyes, libc++ breaks the API defined by the C++ standard:

It should be possible to forward-declare std::mutex because it should reside directly under std, shouldn't it?

Note that the compilation phase, rather than linking phase, is failing. So I don't think the answer to my question should be along the line of "because libc++ employs a different ABI from GNU libstdc++..."

Aucun commentaire:

Enregistrer un commentaire