[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-using-namespace-in-header.cpp
blob6b84e6e70a507d791f7251e6d9075c4f68f6b6b4
1 // RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s
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}}
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;
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}}
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}}
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;
35 // We also shouldn't warn in case of functions.
36 inline void foo() {
37 using namespace warn_in_header_in_global_context;
41 namespace macronamespace {}
42 #define USING_MACRO using namespace macronamespace;
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}}
48 #else
50 #define BE_THE_HEADER
51 #include __FILE__
53 namespace dont_warn {}
54 using namespace dont_warn;
56 // |using namespace| through a macro shouldn't warn if the instantiation is in a
57 // cc file.
58 USING_MACRO
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
66 namespace nowarn_after_line_marker {}
67 using namespace nowarn_after_line_marker;
69 #endif