header.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // RUN: %clang_cc1 -fsyntax-only -Wno-header-guard %s
  2. // RUN: %clang_cc1 -fsyntax-only -Wheader-guard %s 2>&1 | FileCheck %s
  3. #include "Inputs/good-header-guard.h"
  4. #include "Inputs/no-define.h"
  5. #include "Inputs/different-define.h"
  6. #include "Inputs/out-of-order-define.h"
  7. #include "Inputs/tokens-between-ifndef-and-define.h"
  8. #include "Inputs/unlikely-to-be-header-guard.h"
  9. #include "Inputs/bad-header-guard.h"
  10. // CHECK: In file included from {{.*}}header.cpp:{{[0-9]*}}:
  11. // CHECK: {{.*}}bad-header-guard.h:1:9: warning: 'bad_header_guard' is used as a header guard here, followed by #define of a different macro
  12. // CHECK: {{^}}#ifndef bad_header_guard
  13. // CHECK: {{^}} ^~~~~~~~~~~~~~~~
  14. // CHECK: {{.*}}bad-header-guard.h:2:9: note: 'bad_guard' is defined here; did you mean 'bad_header_guard'?
  15. // CHECK: {{^}}#define bad_guard
  16. // CHECK: {{^}} ^~~~~~~~~
  17. // CHECK: {{^}} bad_header_guard
  18. #include "Inputs/bad-header-guard-defined.h"
  19. // CHECK: In file included from {{.*}}header.cpp:{{[0-9]*}}:
  20. // CHECK: {{.*}}bad-header-guard-defined.h:1:2: warning: 'foo' is used as a header guard here, followed by #define of a different macro
  21. // CHECK: {{^}}#if !defined(foo)
  22. // CHECK: {{^}} ^~
  23. // CHECK: {{.*}}bad-header-guard-defined.h:2:9: note: 'goo' is defined here; did you mean 'foo'?
  24. // CHECK: {{^}}#define goo
  25. // CHECK: {{^}} ^~~
  26. // CHECK: {{^}} foo
  27. #include "Inputs/multiple.h"
  28. #include "Inputs/multiple.h"
  29. #include "Inputs/multiple.h"
  30. #include "Inputs/multiple.h"
  31. // CHECK: In file included from {{.*}}header.cpp:{{[0-9]*}}:
  32. // CHECK: {{.*}}multiple.h:1:9: warning: 'multiple' is used as a header guard here, followed by #define of a different macro
  33. // CHECK: {{^}}#ifndef multiple
  34. // CHECK: {{^}} ^~~~~~~~
  35. // CHECK: {{.*}}multiple.h:2:9: note: 'multi' is defined here; did you mean 'multiple'?
  36. // CHECK: {{^}}#define multi
  37. // CHECK: {{^}} ^~~~~
  38. // CHECK: {{^}} multiple
  39. // CHECK: 3 warnings generated.