less icon indicating copy to clipboard operation
less copied to clipboard

clang warnings

Open polluks opened this issue 1 year ago • 5 comments

gcc -I. -c -DBINDIR=\"/usr/local/bin\" -DSYSDIR=\"/usr/local/etc\"  -g -O2 option.c
screen.c:741:19: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
        return (tgetflag(capname));
                         ^~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/termcap.h:66:58: note: passing argument to parameter here
extern NCURSES_EXPORT(int) tgetflag (NCURSES_CONST char *);
                                                         ^
screen.c:752:18: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
        return (tgetnum(capname));
                        ^~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/termcap.h:67:57: note: passing argument to parameter here
extern NCURSES_EXPORT(int) tgetnum (NCURSES_CONST char *);
                                                        ^
screen.c:763:18: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
        return (tgetstr(capname, pp));
                        ^~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/termcap.h:63:60: note: passing argument to parameter here
extern NCURSES_EXPORT(char *) tgetstr (NCURSES_CONST char *, char **);
                                                           ^

polluks avatar Jan 21 '24 22:01 polluks

Yeah I've noticed this but I'm not yet sure how to fix it. Clearly NCURSES_CONST should be defined as "const" but for some reason that's not happening.

gwsw avatar Jan 21 '24 22:01 gwsw

By the way I still using ncurses 5.4.

polluks avatar Jan 21 '24 23:01 polluks

Hm, somehow I've updated to ncurses 5.9 and the warning is fixed because termcap.h now defines NCURSES_CONST. I don't want to check this in yet, but can you confirm whether adding this line to screen.c fixes the warnings for you?

diff --git a/screen.c b/screen.c
index 8bdf080..ea0c7be 100644
--- a/screen.c
+++ b/screen.c
@@ -68,6 +68,7 @@ extern int fd0;
 #endif
 #endif
 
+#define NCURSES_CONST const
 #if HAVE_NCURSESW_TERMCAP_H
 #include <ncursesw/termcap.h>
 #else

gwsw avatar Jan 22 '24 01:01 gwsw

still the same because of

[...]
#undef  NCURSES_VERSION 
#define NCURSES_VERSION "6.0" 
 
#include <ncurses_dll.h> 
 
#ifdef __cplusplus 
extern "C" 
{ 
#endif /* __cplusplus */ 
 
#include <sys/types.h> 
 
#undef  NCURSES_CONST  
#define NCURSES_CONST /*nothing*/  

the header says 6.0 but the library 5.4?! https://github.com/python/cpython/issues/109617#issuecomment-1728466271

polluks avatar Jan 22 '24 23:01 polluks

This is weird. My termcap.h has

#define NCURSES_VERSION "5.9"

#include <ncursesw/ncurses_dll.h>

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

#include <sys/types.h>

#undef  NCURSES_CONST 
#define NCURSES_CONST const 

So it seems your 6.0 termcap.h is newer than mine, but regresses to defining NCURSES_CONST as nothing, whereas my "older" 5.9 file defines it correctly. In any case, these warnings seem to be entirely caused by Apple's header files defining NCURSES_CONST incorrectly, and making it impossible to redefine it, so I'm inclined to just leave it as it is and assume that eventually Apple will get it fixed.

gwsw avatar Jan 26 '24 18:01 gwsw

Indeed.

$ otool -L less                 
less:
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)

BTW MacPorts has 6.4 5.7 without const!? https://opensource.apple.com/source/ncurses/ncurses-57/ncurses/include/termcap.h.auto.html

@gwsw It's a known issue! However we are not using CMake.

polluks avatar Jan 27 '24 15:01 polluks