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

Enable and fix more GCC warnings #2747

Closed
wants to merge 5 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@MarcelRaad
Member

MarcelRaad commented Jul 14, 2018

This enables the following GCC flags:

When building with --enable-werror:

  • -pedantic-errors for GCC >= 5, which rejects some constructs which are no valid C and turns some undefined behavior into compile errors

When building with --enable-warnings:

  • -Wbad-function-cast, which was already enabled for clang, but not for GCC as it's a little stricter there - would have found #2696 also with GCC
  • -Wimplicit-fallthrough=4 instead of the default 3, which makes the fallthrough comments more uniform
  • -Wold-style-definition
  • -ftree-vrp and -fdelete-null-pointer-checks, so that -Warray-bounds and -Wnull-dereference also work without --enable-optimize
  • level 2 instead of the default level 1 for -Wformat, -Warray-bounds, and -Wunused-const-variable

Also removes some unused definitions, but unfortunately the corresponding warning flag cannot be enabled as some occurrences are hard to fix.

Tested with

  • GCC 4.4 through 7 on Ubuntu 16.04 targeting Linux, Win64, Win32
  • GCC 4.8 on OpenSUSE Leap 42
  • GCC 4.8 on SLES 12
  • GCC 6 on MinGW/MSYS
  • GCC 7 on MinGW-w64/MSYS2 targeting Win64, Win32, MSYS
  • GCC 7 on Cygwin
@bagder

bagder approved these changes Jul 16, 2018

@@ -62,6 +62,7 @@ int test(char *URL)
struct curl_forms formarray[3];
size_t formlength = 0;
char flbuf[32];
long contentlength = 0;

This comment has been minimized.

@bagder

bagder Jul 16, 2018

Member

shouldn't this be a curl_off_t ?

This comment has been minimized.

@MarcelRaad

MarcelRaad Jul 16, 2018

Member

The deprecated CURLFORM_CONTENTSLENGTH used here uses long. I used the same cast sequence as in formdata.c. The newer CURLFORM_CONTENTLEN uses curl_off_t. If you want, I can switch to that in a separate commit before this one.

/* Use a form array for the non-copy test. */
formarray[0].option = CURLFORM_PTRCONTENTS;
formarray[0].value = data;
formarray[1].option = CURLFORM_CONTENTSLENGTH;
formarray[1].value = (char *) strlen(data) - 1;
formarray[1].value = (char *)(size_t)contentlength;

This comment has been minimized.

@bagder

bagder Jul 16, 2018

Member

and this too. Even if they're highly likely to use the same size...

@@ -94,11 +95,13 @@ int test(char *URL)
goto test_cleanup;
}

contentlength = (long)(strlen(data) - 1);

This comment has been minimized.

@bagder

bagder Jul 16, 2018

Member

... and this

@bagder

This comment has been minimized.

Member

bagder commented Aug 21, 2018

@MarcelRaad, what's the reason this is marked for next feature window and can't go in already now?

@MarcelRaad

This comment has been minimized.

Member

MarcelRaad commented Aug 21, 2018

@bagder The reason at that time was that I thought I wouldn't have enough time to see if all autobuilds pass without new warnings and fix them if not for 7.61.1. As the release date is now September 5, I'll merge right now and watch the autobuilds. Thanks!

@bagder

This comment has been minimized.

Member

bagder commented Aug 21, 2018

Excellent! 👍

MarcelRaad added some commits Jul 9, 2018

configure: conditionally enable pedantic-errors
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes #2747
curl-compilers: enable -Wbad-function-cast on GCC
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes #2747
curl-compilers: enable -Wimplicit-fallthrough=4 for GCC
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes #2747
Enable more GCC warnings
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes #2747

@MarcelRaad MarcelRaad force-pushed the MarcelRaad:gcc-warnings branch from 7e605fb to 7e34a58 Aug 21, 2018

MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018

configure: conditionally enable pedantic-errors
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747

MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018

curl-compilers: enable -Wbad-function-cast on GCC
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747

MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018

curl-compilers: enable -Wimplicit-fallthrough=4 for GCC
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747

MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018

Enable more GCC warnings
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747

@MarcelRaad MarcelRaad deleted the MarcelRaad:gcc-warnings branch Aug 21, 2018

xquery added a commit to xquery/curl that referenced this pull request Sep 3, 2018

xquery added a commit to xquery/curl that referenced this pull request Sep 3, 2018

configure: conditionally enable pedantic-errors
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747

xquery added a commit to xquery/curl that referenced this pull request Sep 3, 2018

curl-compilers: enable -Wbad-function-cast on GCC
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747

xquery added a commit to xquery/curl that referenced this pull request Sep 3, 2018

curl-compilers: enable -Wimplicit-fallthrough=4 for GCC
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747

xquery added a commit to xquery/curl that referenced this pull request Sep 3, 2018

Enable more GCC warnings
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747

falconindy added a commit to falconindy/curl that referenced this pull request Sep 10, 2018

falconindy added a commit to falconindy/curl that referenced this pull request Sep 10, 2018

configure: conditionally enable pedantic-errors
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747

falconindy added a commit to falconindy/curl that referenced this pull request Sep 10, 2018

curl-compilers: enable -Wbad-function-cast on GCC
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747

falconindy added a commit to falconindy/curl that referenced this pull request Sep 10, 2018

curl-compilers: enable -Wimplicit-fallthrough=4 for GCC
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747

falconindy added a commit to falconindy/curl that referenced this pull request Sep 10, 2018

Enable more GCC warnings
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747

@lock lock bot locked as resolved and limited conversation to collaborators Nov 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.