Douglas Gregor | d6a49bb | 2011-03-18 16:10:52 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s |
| 2 | |
Nico Weber | 776b7ac | 2012-11-05 22:49:03 +0000 | [diff] [blame] | 3 | #ifdef BE_THE_HEADER |
Nico Weber | 776b7ac | 2012-11-05 22:49:03 +0000 | [diff] [blame] | 4 | namespace warn_in_header_in_global_context {} |
| 5 | using namespace warn_in_header_in_global_context; // expected-warning {{using namespace directive in global context in header}} |
| 6 | |
| 7 | // While we want to error on the previous using directive, we don't when we are |
| 8 | // inside a namespace |
| 9 | namespace dont_warn_here { |
| 10 | using namespace warn_in_header_in_global_context; |
| 11 | } |
| 12 | |
| 13 | // We should warn in toplevel extern contexts. |
| 14 | namespace warn_inside_linkage {} |
| 15 | extern "C++" { |
| 16 | using namespace warn_inside_linkage; // expected-warning {{using namespace directive in global context in header}} |
| 17 | } |
| 18 | |
| 19 | // This is really silly, but we should warn on it: |
| 20 | extern "C++" { |
| 21 | extern "C" { |
| 22 | extern "C++" { |
| 23 | using namespace warn_inside_linkage; // expected-warning {{using namespace directive in global context in header}} |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // But we shouldn't warn in extern contexts inside namespaces. |
| 29 | namespace dont_warn_here { |
| 30 | extern "C++" { |
| 31 | using namespace warn_in_header_in_global_context; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | // We also shouldn't warn in case of functions. |
| 36 | inline void foo() { |
| 37 | using namespace warn_in_header_in_global_context; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | namespace macronamespace {} |
| 42 | #define USING_MACRO using namespace macronamespace; |
| 43 | |
| 44 | // |using namespace| through a macro should warn if the instantiation is in a |
| 45 | // header. |
| 46 | USING_MACRO // expected-warning {{using namespace directive in global context in header}} |
| 47 | |
| 48 | #else |
| 49 | |
| 50 | #define BE_THE_HEADER |
| 51 | #include __FILE__ |
Douglas Gregor | d6a49bb | 2011-03-18 16:10:52 +0000 | [diff] [blame] | 52 | |
| 53 | namespace dont_warn {} |
| 54 | using namespace dont_warn; |
| 55 | |
Nico Weber | 2166948 | 2011-04-02 19:45:15 +0000 | [diff] [blame] | 56 | // |using namespace| through a macro shouldn't warn if the instantiation is in a |
| 57 | // cc file. |
| 58 | USING_MACRO |
Nico Weber | 776b7ac | 2012-11-05 22:49:03 +0000 | [diff] [blame] | 59 | |
| 60 | #endif |