Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Error on Cygwin #2529

Closed
rkaminsk opened this issue Sep 18, 2022 · 6 comments · Fixed by #2540
Closed

Build Error on Cygwin #2529

rkaminsk opened this issue Sep 18, 2022 · 6 comments · Fixed by #2540

Comments

@rkaminsk
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

I get the following error using gcc 11.3.0 on cygwin:

/cygdrive/c/projects/clingo/third_party/catch/src/catch2/../catch2/catch_tostring.hpp:214:33: error: there are no arguments to 'strnlen' that depend on a template parameter, so a declaration of 'strnlen' must be available [-fpermissive]
  214 |                 StringRef( str, strnlen( str, SZ ) ) );

What about using strnlen_s instead? The only problem I see is that additional macros would have to be defined but since the templates are fully instantiated, the required code could be moved to the source file.

There might also be another header providing a strnlen. I could dig a little deeper if help is required.

Platform information:

  • OS: Windows + Cygwin
  • Compiler+version: GCC v11.3.0
  • Catch version: v3.1.0
@rkaminsk
Copy link
Contributor Author

I just saw that this has already been reported in #2511.

@rkaminsk
Copy link
Contributor Author

Just a simple workaround that could easily be extended to other platforms:

inline std::size_t catch_strnlen(const char *str, std::size_t n)
{
#ifdef __CYGWIN__
    if (str == nullptr || n == 0) {
        return 0;
    }

    std::size_t len = 0;
    while (len < n && str[len] != '\0') {
        ++len;
    }

    return len;
#else
    return strnlen(str, n);
#endif
}

@dimztimz
Copy link
Contributor

There is a better solution with memchr() or with its C++ equivalent std::char_traits::find().

@rkaminsk
Copy link
Contributor Author

rkaminsk commented Sep 27, 2022

So then this can be written portably in C++11 using

inline std::size_t catch_strnlen(const char *str, std::size_t n)
{
    auto ret = std::memchr(str, '\0', n);
    if (ret != nullptr) {
        return ret - str;
    }
    return n;
}

without resorting to macros.

@neheb
Copy link
Contributor

neheb commented Oct 3, 2022

you sure it's not hidden behind _GNU_SOURCE?

@rkaminsk
Copy link
Contributor Author

rkaminsk commented Oct 3, 2022

you sure it's not hidden behind _GNU_SOURCE?

It is part of the strings library: https://en.cppreference.com/w/cpp/string/byte/memchr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants