cmake-use-cmstrlen-fixit.cxx 591 B

12345678910111213141516171819202122232425262728293031323334353637
  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)cmStrLen("Hello");
  22. (void)cmStrLen("Goodbye");
  23. (void)cmStrLen("Hola");
  24. (void)cmStrLen("Bonjour");
  25. // No correction needed
  26. (void)ns2::strlen("Salve");
  27. (void)cmStrLen("Konnichiwa");
  28. (void)strlen(s0);
  29. return 0;
  30. }