Skip to content

Please address -Wshadow warnings #282

@djfy

Description

@djfy

When compiling the following code,

#include <httplib.h>

int main()
{
  httplib::Client cli("localhost", 1234);
  return 0;
}

with the flags -Wall -Wextra -Werror -Wpedantic -Wshadow, there are multiple -Wshadow warnings emitted on compilation:

In file included from /test_realm/main.cpp:1:0:
/test_realm/lib/cpp-httplib/httplib.h: In lambda function:
/test_realm/lib/cpp-httplib/httplib.h:1863:54: error: declaration of 'const char* e' shadows a parameter [-Werror=shadow]
     split(b, e, '=', [&](const char *b, const char *e) {
                                                      ^
/test_realm/lib/cpp-httplib/httplib.h:1860:66: note: shadowed declaration is here
   split(&s[0], &s[s.size()], '&', [&](const char *b, const char *e) {
                                                                  ^
/test_realm/lib/cpp-httplib/httplib.h:1863:54: error: declaration of 'const char* b' shadows a parameter [-Werror=shadow]
     split(b, e, '=', [&](const char *b, const char *e) {
                                                      ^
/test_realm/lib/cpp-httplib/httplib.h:1860:51: note: shadowed declaration is here
   split(&s[0], &s[s.size()], '&', [&](const char *b, const char *e) {
                                                   ^
/test_realm/lib/cpp-httplib/httplib.h: In lambda function:
/test_realm/lib/cpp-httplib/httplib.h:1894:25: error: declaration of 'm' shadows a previous local [-Werror=shadow]
             std::cmatch m;
                         ^
/test_realm/lib/cpp-httplib/httplib.h:1887:17: note: shadowed declaration is here
     std::smatch m;
                 ^
/test_realm/lib/cpp-httplib/httplib.h: In member function 'bool httplib::detail::MultipartFormDataParser::parse(const char*, size_t, T, U)':
/test_realm/lib/cpp-httplib/httplib.h:2047:16: error: declaration of 'pos' shadows a previous local [-Werror=shadow]
           auto pos = buf_.find(pattern);
                ^~~
/test_realm/lib/cpp-httplib/httplib.h:2038:14: note: shadowed declaration is here
         auto pos = buf_.find(crlf_);
              ^~~
/test_realm/lib/cpp-httplib/httplib.h: In lambda function:
/test_realm/lib/cpp-httplib/httplib.h:2386:37: error: declaration of 'size_t length' shadows a parameter [-Werror=shadow]
                                 Done) { provider(offset, length, sink); };
                                     ^
/test_realm/lib/cpp-httplib/httplib.h:2380:12: note: shadowed declaration is here
     size_t length,
            ^~~~~~
/test_realm/lib/cpp-httplib/httplib.h: In instantiation of 'bool httplib::detail::MultipartFormDataParser::parse(const char*, size_t, T, U) [with T = std::function<bool(const std::__cxx11::basic_string<char>&, const char*, long long unsigned int)>; U = std::function<bool(const std::__cxx11::basic_string<char>&, const httplib::MultipartFile&)>; size_t = long long unsigned int]':
/test_realm/lib/cpp-httplib/httplib.h:2857:91:   required from here
/test_realm/lib/cpp-httplib/httplib.h:2047:16: error: declaration of 'pos' shadows a previous local [-Werror=shadow]
           auto pos = buf_.find(pattern);
                ^~~
/test_realm/lib/cpp-httplib/httplib.h:2038:14: note: shadowed declaration is here
         auto pos = buf_.find(crlf_);
              ^~~

It would be great if these could be addressed.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions