Skip to content

Commit

Permalink
Silence -Wcast-qual warnings showing up with newer version of g++.
Browse files Browse the repository at this point in the history
Somewhen between gcc 11 and a 14 pre-release, g++ started to complain
about the C-style casts:

subprocess.h: In function ‘int subprocess_create_ex(const char* const*, int, const char* const*, subprocess_s*)’:
subprocess.h:877:27: warning: cast from type ‘const char* const*’ to type ‘char* const*’ casts away qualifiers [-Wcast-qual]
  877 |                           (char *const *)commandLine, used_environment)) {
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~

When compiling with GCC in C-mode, the issue is still there btw. The
pragmas existing for clang are needed for GCC as well.
  • Loading branch information
Harri Porten committed May 14, 2024
1 parent 7e59b69 commit a7c7c3b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions subprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ int subprocess_create_ex(const char *const commandLine[], int options,
#pragma clang diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wold-style-cast"
#endif
used_environment = (char *const *)environment;
used_environment = SUBPROCESS_CONST_CAST(char *const *, environment);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
Expand Down Expand Up @@ -874,13 +874,15 @@ int subprocess_create_ex(const char *const commandLine[], int options,
if (subprocess_option_search_user_path ==
(options & subprocess_option_search_user_path)) {
if (0 != posix_spawnp(&child, commandLine[0], &actions, SUBPROCESS_NULL,
(char *const *)commandLine, used_environment)) {
SUBPROCESS_CONST_CAST(char *const *, commandLine),
used_environment)) {
posix_spawn_file_actions_destroy(&actions);
return -1;
}
} else {
if (0 != posix_spawn(&child, commandLine[0], &actions, SUBPROCESS_NULL,
(char *const *)commandLine, used_environment)) {
SUBPROCESS_CONST_CAST(char *const *, commandLine),
used_environment)) {
posix_spawn_file_actions_destroy(&actions);
return -1;
}
Expand Down

0 comments on commit a7c7c3b

Please sign in to comment.