Skip to content

Add new warnings and silence them - #2307

Closed
cooljeanius wants to merge 2 commits into
curl:masterfrom
cooljeanius:master
Closed

cooljeanius wants to merge 2 commits into
curl:masterfrom
cooljeanius:master

Conversation

@cooljeanius

Copy link
Copy Markdown
Contributor

GCC 6 and 7 added some new warning flags that aren't a part of -Wall or -Wextra, so this pull request adds them to the configure script where the rest of the warnings go. It then also silences the new warnings created by these additions. Built on x86_64-apple-darwin10.8.0 with GCC 7.

@bagder bagder added the build label Feb 12, 2018
@bagder

bagder commented Feb 12, 2018

Copy link
Copy Markdown
Member

Lovely contribution!

Let's just see how much trouble we get from them and if they can all land. The current CI failure on windows says: error C2065: 'sa_family_t' : undeclared identifier ...

@jay

jay commented Feb 12, 2018

Copy link
Copy Markdown
Member

error C2065: 'sa_family_t' : undeclared identifier

Yes I get that here as well. I've searched the SDK and I don't see that type defined anywhere. h_addrtype is a short in Windows, short h_addrtype; /* host address type */

@cooljeanius

cooljeanius commented Feb 12, 2018 •

Copy link
Copy Markdown
Contributor Author

Looking up, apparently sa_family_t is specified by POSIX as being declared in <sys/socket.h>. Does Windows have <sys/socket.h>? I don't have a Windows system to test on...

Looking at the ifdefery in some of the configure tests, I guess <winsock2.h> is the equivalent of it... the autoconf script already has a check for <sys/socket.h>, but looking at the Appveyor build log, apparently configuring with cmake doesn't check for it, and I don't know enough about cmake to make it check for it...

@jay

jay commented Feb 12, 2018 •

Copy link
Copy Markdown
Member

Why does it need to be sa_family_t? sockaddr_in sin_family is short as well in Windows. https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496.aspx Is it larger on other platforms? I see for posix The <sys/socket.h> header shall define the unsigned integer type sa_family_t. but it doesn't say what size.

@cooljeanius

Copy link
Copy Markdown
Contributor Author

On my system sa_family_t is uint8_t, which is actually unsigned char

@jay

jay commented Feb 13, 2018

Copy link
Copy Markdown
Member

On my system sa_family_t is uint8_t, which is actually unsigned char

Ok. I guess we could typedef it for Windows, but I wonder what to do about other systems that don't have it.

@bagder

bagder commented Feb 13, 2018

Copy link
Copy Markdown
Member

To use this type in the code without friction, I don't see how we can avoid adding #ifdef and/or configure/cmake magic for it. Which of the new compiler flags causes a warning on this line without this change?

@cooljeanius

Copy link
Copy Markdown
Contributor Author

It's from -Wconversion, which is actually an old compiler flag, not one of the new ones I added. Maybe I should have saved that part for a separate pull request...

@bagder

bagder commented Feb 15, 2018

Copy link
Copy Markdown
Member

It's from -Wconversion, which is actually an old compiler flag, not one of the new ones I added

That makes me even more curious. We build (almost) every commit on macos warning-free so how did you get a warning there that we didn't?

@cooljeanius

Copy link
Copy Markdown
Contributor Author

That makes me even more curious. We build (almost) every commit on macos warning-free
so how did you get a warning there that we didn't?

Old warning flag but new compiler; -Wconversion might have started warning on things it didn't used to warn about in GCC 7 (in which case it might be a GCC bug...)

@mkauf

mkauf commented Feb 15, 2018

Copy link
Copy Markdown
Contributor

That makes me even more curious. We build (almost) every commit on macos warning-free so how did you get a warning there that we didn't?

There is a problem with the automated macOS builds. The configure script thinks that the compiler is clang. Probably that's true, and clang is used instead of gcc. For example https://travis-ci.org/curl/curl/jobs/341864424 :

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
...
checking if compiler is clang... yes
checking if compiler is GNU C... no

-Wconversion is enabled only for gcc.

The warnings also appear on NetBSD (gcc 5.4.0): https://curl.haxx.se/dev/log.cgi?id=20180215033441-2650#prob1

@mkauf

mkauf commented Feb 19, 2018

Copy link
Copy Markdown
Contributor

It's possible to use a "real" gcc on macOS, see travis-ci/travis-ci#2423

@bagder

bagder commented Mar 26, 2018

Copy link
Copy Markdown
Member

How about this?

At the top of the file somewhere:

/* for systems that don't detect this, use a sensible default */
#ifndef CURL_SA_FAMILY_T
#define CURL_SA_FAMILY_T unsigned short
#endif

Use CURL_SA_FAMILY_T in the typecast.

Then add the following patch to configure.ac to make it try to detect what type to use for this particular system:

diff --git a/configure.ac b/configure.ac
index 798fa5f1e..d1c1a8f93 100755
--- a/configure.ac
+++ b/configure.ac
@@ -3490,10 +3490,30 @@ AC_CHECK_TYPE([bool],[
 #ifdef HAVE_STDBOOL_H
 #include <stdbool.h>
 #endif
 ])
 
+# check for sa_family_t
+AC_CHECK_TYPE(sa_family_t,
+   AC_DEFINE(CURL_SA_FAMILY_T, sa_family_t, [IP address type in sockaddr]),
+   [
+   # The windows name?
+   AC_CHECK_TYPE(ADDRESS_FAMILY,
+     AC_DEFINE(CURL_SA_FAMILY_T, ADDRESS_FAMILY, [IP address type in sockaddr]),
+     AC_DEFINE(CURL_SA_FAMILY_T, unsigned short, [IP address type in sockaddr]),
+    [
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+    ])
+   ],
+[
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+])
+
 AC_MSG_CHECKING([if time_t is unsigned])
 AC_RUN_IFELSE([
   AC_LANG_SOURCE([[
   #include <time.h>
   #include <limits.h>

@cooljeanius

Copy link
Copy Markdown
Contributor Author

How about this?

That looks like it would probably work; I don't think I can add that myself though because I forgot the "don't send pull requests from master" rule of thumb and have some other irrelevant commits that would get mixed in if I pushed them like I'd have to if also pushing your patch...

@bagder bagder mentioned this pull request Apr 6, 2018
@bagder

bagder commented Apr 6, 2018

Copy link
Copy Markdown
Member

All right, thanks! I took your work and merged it with my polish attempts so the continuation is now in #2463 and this can be closed.

@bagder bagder closed this Apr 6, 2018
@lock lock Bot locked as resolved and limited conversation to collaborators Jul 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

4 participants