-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should SF.7 avoid to limit its applicability to when the directive is at global scope? #2208
Comments
Editors call: Thanks!
We wonder if this is the problem, because all three files are adding things to a namespace and so normally would be expected to be owned by the same maintainer? And the author of |
Thanks for the reply, @hsutter. It took a bit to get my head around the past, but I think I've reconstructed it, which also shows I've been a bit inaccurate when I posted the issue in June. At that time, I contributed to that part of the codebase where So the answer to
is that I contributed to that sub-codebase and that namespace. But I had already written the utility in a header in the part of the codebase I usually work with, And I have to say, luckily I tried to compile that in my codebase first, because otherwise the unit test I eventually wrote in the But my point is that Yes, if I knew of that But it's not really just "if I knew", it's "if I knew and remembered and had it ready in the L1 cache of my brain, if not a register". Plus, owners of codebases change with time. |
"Don’t write using namespace in a header file" means I can't do this in a header file: inline func(X& x) {
using namespace std;
// ...
blah(x);
} Now some people say preventing that is good (and I've been ridiculed on stackoverflow by such people) but the risk is that So maybe what you're asking for is for SF.7 to talk about namespace scope (i.e. outside of function bodies) not global scope. That would have avoided your problem, without banning the code above that uses it in a body of an inline function. But I think the use of global scope is intentional, because it still allows importing all names from one namespace into another: namespace mine {
using namespace yours;
} The broken-header.hpp case just seems like a bad use of |
Yeah, sorry, I thought I had written it somewhere! Yes, I'm suggesting a change along the lines of
As regards the snippet
what would a justifiable usecase be? Let me clarify what I mean by "justifiable". If the motivation for the snippet above in a header file was "I'm writing stuff in |
Today I've spent quite some time to discover why adding something like
in a header of mine was causing havoc in a seemingly unrealted translation unit (unrelated to the one I was compiling when I made the change). The error was along these lines, where
innocent-header.hpp
is the only file I own:The problem was a using directive:
The failing translation unit was therefore looking like this:
where the order of inclusion of
broken-header.hpp
andinnocent-header.hpp
is irrelevant.I wouldn't say that
thoughtless-header.hpp
is innocent, but they could have made the mistake of writingfoo::detailFooBar
instead offoo::bar::baz::detail::FooBar
just because they've distractedly Tab-completed with their IDE.But I think that the real problem is still the
using namepspace
.So why shouldn't we change the title of SF.7 the following?
The text was updated successfully, but these errors were encountered: