cmake-use-cmstrlen.cxx 757 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <cstring>
  2. template <size_t N>
  3. constexpr size_t cmStrLen(const char (& /*str*/)[N])
  4. {
  5. return N - 1;
  6. }
  7. namespace ns1 {
  8. using std::strlen;
  9. }
  10. namespace ns2 {
  11. std::size_t strlen(const char* str)
  12. {
  13. return std::strlen(str);
  14. }
  15. }
  16. int main()
  17. {
  18. // String variable used for calling strlen() on a variable
  19. auto s0 = "howdy";
  20. // Correction needed
  21. (void)strlen("Hello");
  22. (void)::strlen("Goodbye");
  23. (void)std::strlen("Hola");
  24. (void)ns1::strlen("Bonjour");
  25. (void)(sizeof("Hallo") - 1);
  26. (void)(4 + sizeof("Hallo") - 1);
  27. (void)(sizeof "Hallo" - 1);
  28. (void)(4 + sizeof "Hallo" - 1);
  29. // No correction needed
  30. (void)ns2::strlen("Salve");
  31. (void)cmStrLen("Konnichiwa");
  32. (void)strlen(s0);
  33. (void)(sizeof("Hallo") - 2);
  34. return 0;
  35. }