https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110092
--- Comment #3 from Piotr Nycz <piotrwn1 at gmail dot com> --- (In reply to Jonathan Wakely from comment #2) > (In reply to Piotr Nycz from comment #0) > > So, probably it is doable to add warning like: "bist/shared_ptr.h is an > > internal header file, included by other library headers. Do not attempt to > > use it directly. Use <memory> instead" > > We could add this to <bits/shared_ptr.h>: > > #ifndef _GLIBCXX_MEMORY > # error Do not include <bits/shared_ptr.h> directly, include <memory> > instead. > #endif > > But then you'd get an error when you include <regex>, or <filesystem>, or > <chrono>, or any of the other headers that use std::shared_ptr internally. > > So we'd have to do: > > #if !defined _GLIBCXX_MEMORY && !defined _GLIBCXX_CHRONO && !defined > _GLIBCXX_REGEX \ > && ! defined ... > > And that would be a pain to maintain. > > And then it would still not give an error for this, even though it's still > wrong: > > #include <chrono> > #include <bits/shared_ptr.h> > std::shared_ptr<int> p; > > So I don't think this can really be solved in the compiler without a lot of > work to hardcode special handling for each of those headers. Well, I did not mean to make such a mess in compiler headers for sure. But if it is somehow detectable that the compiler is compiling something in user directories (not in std library, compiler stuff) then maybe it can be detected by compiler that something internal is included in user file. I am just guessing, I do not have any knowledge about how gcc compiler is working. I see that system headers have some pragma telling it is system header and these internal headers have comment in `@file` section that it is internal. But of course - it could be done by some other tool like clang-tidy, if this is a big problem. I just think it would be nice to have such warning - so it is more "new feature request" than bug report.