https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110092
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- (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.