cxx1z-nested-namespace-definition.cpp 945 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // RUN: cp %s %t
  2. // RUN: %clang_cc1 -fsyntax-only -verify %s
  3. // RUN: not %clang_cc1 -x c++ -fixit %t -Werror -DFIXIT
  4. // RUN: %clang_cc1 -x c++ %t -DFIXIT
  5. // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z -Wc++14-compat
  6. namespace foo1::foo2::foo3 {
  7. #if __cplusplus <= 201400L
  8. // expected-warning@-2 {{nested namespace definition is a C++1z extension; define each namespace separately}}
  9. #else
  10. // expected-warning@-4 {{nested namespace definition is incompatible with C++ standards before C++1z}}
  11. #endif
  12. int foo(int x) { return x; }
  13. }
  14. #ifndef FIXIT
  15. inline namespace goo::bar { // expected-error {{nested namespace definition cannot be 'inline'}} expected-warning 0-1{{C++11 feature}}
  16. int n;
  17. }
  18. int m = goo::bar::n;
  19. #endif
  20. int foo(int x) {
  21. return foo1::foo2::foo3::foo(x);
  22. }
  23. namespace bar1 {
  24. namespace bar2 {
  25. namespace bar3 {
  26. int bar(int x) { return x; }
  27. }
  28. }
  29. }
  30. int bar(int x) {
  31. return bar1::bar2::bar3::bar(x);
  32. }