Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s
      2 
      3 #ifdef BE_THE_HEADER
      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__
     52 
     53 namespace dont_warn {}
     54 using namespace dont_warn;
     55 
     56 // |using namespace| through a macro shouldn't warn if the instantiation is in a
     57 // cc file.
     58 USING_MACRO
     59 
     60 // Check behavior of line markers.
     61 namespace warn_header_with_line_marker {}
     62 # 1 "XXX.h" 1
     63 using namespace warn_header_with_line_marker; // expected-warning {{using namespace directive in global context in header}}
     64 # 70 "warn-using-namespace-in-header.cpp" 2
     65 
     66 namespace nowarn_after_line_marker {}
     67 using namespace nowarn_after_line_marker;
     68 
     69 #endif
     70