blob: f68b99893aae7d7dee6069bcd9aefa97ec1c07cf [file] [log] [blame]
Douglas Gregord6a49bb2011-03-18 16:10:52 +00001// RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s
2
Nico Weber776b7ac2012-11-05 22:49:03 +00003#ifdef BE_THE_HEADER
Nico Weber776b7ac2012-11-05 22:49:03 +00004namespace warn_in_header_in_global_context {}
5using 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
9namespace dont_warn_here {
10using namespace warn_in_header_in_global_context;
11}
12
13// We should warn in toplevel extern contexts.
14namespace warn_inside_linkage {}
15extern "C++" {
16using 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:
20extern "C++" {
21extern "C" {
22extern "C++" {
23using 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.
29namespace dont_warn_here {
30extern "C++" {
31using namespace warn_in_header_in_global_context;
32}
33}
34
35// We also shouldn't warn in case of functions.
36inline void foo() {
37 using namespace warn_in_header_in_global_context;
38}
39
40
41namespace 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.
46USING_MACRO // expected-warning {{using namespace directive in global context in header}}
47
48#else
49
50#define BE_THE_HEADER
51#include __FILE__
Douglas Gregord6a49bb2011-03-18 16:10:52 +000052
53namespace dont_warn {}
54using namespace dont_warn;
55
Nico Weber21669482011-04-02 19:45:15 +000056// |using namespace| through a macro shouldn't warn if the instantiation is in a
57// cc file.
58USING_MACRO
Nico Weber776b7ac2012-11-05 22:49:03 +000059
60#endif