https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66180
--- Comment #8 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- If I change foo1.cpp from comment5 to: #include <memory> namespace first{ class A { int i; }; } using namespace first; class G { std::unique_ptr<A> foo() const; }; std::unique_ptr<A> G::foo() const { return std::make_unique<A>(); } it works fine. So it looks like a bug after all, because an anonymous namespace should be equivalent to: namespace _compiler_generated_name { ... } using namespace _compiler_generated_name;