On Sat, Mar 19, 2011 at 3:55 PM, Douglas Gregor <[email protected]> wrote:
> On Mar 19, 2011, at 3:27 AM, Sebastian Redl <[email protected]>
> wrote:
>> Do we want to warn about this?
>>
>> extern "C++" {
>> using namespace foo;
>> }
>>
>> Because the fact that extern blocks are decl contexts has bitten me before,
>> and the above suggestion would fall prey to the same issue.
>
> Good point! Yes, we do want to warn about that.
Is the attached patch sufficient, or are there other cases I should be
checking for?
-- Elliot
Index: test/SemaCXX/warn-using-namespace-in-header.h
===================================================================
--- test/SemaCXX/warn-using-namespace-in-header.h (revision 128154)
+++ test/SemaCXX/warn-using-namespace-in-header.h (working copy)
@@ -13,3 +13,9 @@
namespace dont_warn_here {
using namespace warn_in_header_in_global_context;
}
+
+// We should warn in toplevel extern contexts.
+namespace warn_inside_linkage {}
+extern "C++" {
+using namespace warn_inside_linkage;
+}
Index: test/SemaCXX/warn-using-namespace-in-header.cpp
===================================================================
--- test/SemaCXX/warn-using-namespace-in-header.cpp (revision 128154)
+++ test/SemaCXX/warn-using-namespace-in-header.cpp (working copy)
@@ -7,3 +7,14 @@
// Warning is actually in the header but only the cpp file gets scanned.
// expected-warning {{using namespace directive in global context in header}}
+
+
+
+
+
+
+
+
+
+// Warn inside linkage specs too.
+// expected-warning {{using namespace directive in global context in header}}
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp (revision 128154)
+++ lib/Sema/SemaDeclCXX.cpp (working copy)
@@ -3923,7 +3923,8 @@
SS.getWithLocInContext(Context),
IdentLoc, Named, CommonAncestor);
- if (CurContext->getDeclKind() == Decl::TranslationUnit &&
+ if ((CurContext->getDeclKind() == Decl::TranslationUnit ||
+ CurContext->getDeclKind() == Decl::LinkageSpec) &&
!SourceMgr.isFromMainFile(IdentLoc)) {
Diag(IdentLoc, diag::warn_using_directive_in_header);
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits