brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 6b84e6e Raw
70 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s2 3#ifdef BE_THE_HEADER4namespace 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 are8// inside a namespace9namespace 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 a45// header.46USING_MACRO // expected-warning {{using namespace directive in global context in header}}47 48#else49 50#define BE_THE_HEADER51#include __FILE__52 53namespace dont_warn {}54using namespace dont_warn;55 56// |using namespace| through a macro shouldn't warn if the instantiation is in a57// cc file.58USING_MACRO59 60// Check behavior of line markers.61namespace warn_header_with_line_marker {} 62# 1 "XXX.h" 163using namespace warn_header_with_line_marker; // expected-warning {{using namespace directive in global context in header}}64# 70 "warn-using-namespace-in-header.cpp" 265 66namespace nowarn_after_line_marker {}67using namespace nowarn_after_line_marker;68 69#endif70