sabotage-linux / netbsd-curses

libcurses and dependencies taken from netbsd and brought into a portable shape (at least to musl or glibc)
Other
147 stars 14 forks source link

__scanflike error on musl #51

Closed tch69 closed 2 years ago

tch69 commented 2 years ago

Hi. I'm building tabs from nbase using Clang, and got this error which seems to be related to this ncurses:

/usr/include/curses.h:721:43: error: expected function body after function declarator
int      mvscanw(int, int, const char *, ...) __scanflike(3, 4);
                                              ^
/usr/include/curses.h:731:54: error: expected function body after function declarator
int      mvwscanw(WINDOW *, int, int, const char *, ...) __scanflike(4, 5);
                                                         ^
/usr/include/curses.h:763:31: error: expected function body after function declarator
int      scanw(const char *, ...) __scanflike(1, 2);
                                  ^
/usr/include/curses.h:786:50: error: expected function body after function declarator
int      vw_scanw(WINDOW *, const char *, __va_list) __scanflike(2, 0);
                                                     ^
/usr/include/curses.h:788:49: error: expected function body after function declarator
int      vwscanw(WINDOW *, const char *, __va_list) __scanflike(2, 0);
                                                    ^
/usr/include/curses.h:831:42: error: expected function body after function declarator
int      wscanw(WINDOW *, const char *, ...) __scanflike(2, 3);

A quick grep shows that function was defined in form.h, but adding it didn't solve the problem. And at you said in #46, there's a lot of mismatches growing between NetBSD's version and this version, maybe it caused the problem. What do I need to do make it work?

rofl0r commented 2 years ago

that's odd. which version of clang are you using ? i did the following test under ubuntu 20.04:

#ifndef __printflike
#if __GNUC__ >= 3
#define __printflike(fmtarg, firstvararg)       \
            __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
#define __scanflike(fmtarg, firstvararg)        \
            __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
#else
#define __printflike(fmtarg, firstvararg)       /* nothing */
#define __scanflike(fmtarg, firstvararg)        /* nothing */
#endif
#endif
int      mvprintw(int, int, const char *, ...) __printflike(3, 4);
int      mvscanw(int, int, const char *, ...) __scanflike(3, 4);
int main() {
        int x, y;
        mvscanw(1,2,"foo %d %d", &x, &y);
        return y;
}
# clang --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /root
# clang -c scanflike.c && echo success
success
#

the __scanflike macro is meant to declare the prototypes of scanf-like function with special gcc attributes seen in this test code so it can warn on code that uses the functions decorated with wrong arguments.

btw it appears the macro is unused in form.h now, so it could be removed from there, but the definition in curses.h should kick in just fine for the functions using there.

tch69 commented 2 years ago

Here:

clang version 14.0.0
Target: x86_64-pc-linux-musl
Thread model: posix
InstalledDir: /usr/llvm/bin

Also, as I have just rediscovered how to use markdown, the full error messages are here now

tch69 commented 2 years ago

Welp, I removed <curses.h> and it compiled just fine, turned out errors showed up because nothing used those definitions