Douglas Gregor | d6a49bb | 2011-03-18 16:10:52 +0000 | [diff] [blame] | 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | // Lots of vertical space to make the error line match up with the line of the |
| 7 | // expected line in the source file. |
| 8 | namespace warn_in_header_in_global_context {} |
| 9 | using namespace warn_in_header_in_global_context; |
| 10 | |
| 11 | // While we want to error on the previous using directive, we don't when we are |
| 12 | // inside a namespace |
| 13 | namespace dont_warn_here { |
| 14 | using namespace warn_in_header_in_global_context; |
| 15 | } |
Douglas Gregor | 9172aa6 | 2011-03-26 22:25:30 +0000 | [diff] [blame] | 16 | |
| 17 | // We should warn in toplevel extern contexts. |
| 18 | namespace warn_inside_linkage {} |
| 19 | extern "C++" { |
| 20 | using namespace warn_inside_linkage; |
| 21 | } |
| 22 | |
| 23 | // This is really silly, but we should warn on it: |
| 24 | extern "C++" { |
| 25 | extern "C" { |
| 26 | extern "C++" { |
| 27 | using namespace warn_inside_linkage; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // But we shouldn't warn in extern contexts inside namespaces. |
| 33 | namespace dont_warn_here { |
| 34 | extern "C++" { |
| 35 | using namespace warn_in_header_in_global_context; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // We also shouldn't warn in case of functions. |
| 40 | inline void foo() { |
| 41 | using namespace warn_in_header_in_global_context; |
| 42 | } |
Nico Weber | 2166948 | 2011-04-02 19:45:15 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | namespace macronamespace {} |
| 46 | #define USING_MACRO using namespace macronamespace; |
| 47 | |
| 48 | // |using namespace| through a macro should warn if the instantiation is in a |
| 49 | // header. |
| 50 | USING_MACRO |