Message ID | 20180220165732.26150-1-clemens.gruber@pqgruber.com |
---|---|
State | New |
Headers | show |
Series | [libgpiod] tools: move function attributes to the header file | expand |
2018-02-20 17:57 GMT+01:00 Clemens Gruber <clemens.gruber@pqgruber.com>: > The attributes should be in the definition in the header file. > Otherwise, the noreturn attribute seems to have no effect and GCC > emits several Wimplicit-fallthrough warnings when compiling libgpiod. > This patch fixes those warnings. > > Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com> > --- > src/tools/tools-common.c | 6 ++---- > src/tools/tools-common.h | 5 +++-- > 2 files changed, 5 insertions(+), 6 deletions(-) > Hi Clemens, I'm not getting any warning. What GCC are you using? Bart -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Bartosz, On Tue, Feb 20, 2018 at 06:57:10PM +0100, Bartosz Golaszewski wrote: > 2018-02-20 17:57 GMT+01:00 Clemens Gruber <clemens.gruber@pqgruber.com>: > > The attributes should be in the definition in the header file. > > Otherwise, the noreturn attribute seems to have no effect and GCC > > emits several Wimplicit-fallthrough warnings when compiling libgpiod. > > This patch fixes those warnings. > > > > Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com> > > --- > > src/tools/tools-common.c | 6 ++---- > > src/tools/tools-common.h | 5 +++-- > > 2 files changed, 5 insertions(+), 6 deletions(-) > > > > Hi Clemens, > > I'm not getting any warning. What GCC are you using? I am using GCC 7.3.0. I think the -Wimplicit-fallthrough warning was introduced with 7.x and is enabled by -Wextra. Regards, Clemens -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
2018-02-20 19:27 GMT+01:00 Clemens Gruber <clemens.gruber@pqgruber.com>: > Hi Bartosz, > > On Tue, Feb 20, 2018 at 06:57:10PM +0100, Bartosz Golaszewski wrote: >> 2018-02-20 17:57 GMT+01:00 Clemens Gruber <clemens.gruber@pqgruber.com>: >> > The attributes should be in the definition in the header file. >> > Otherwise, the noreturn attribute seems to have no effect and GCC >> > emits several Wimplicit-fallthrough warnings when compiling libgpiod. >> > This patch fixes those warnings. >> > >> > Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com> >> > --- >> > src/tools/tools-common.c | 6 ++---- >> > src/tools/tools-common.h | 5 +++-- >> > 2 files changed, 5 insertions(+), 6 deletions(-) >> > >> >> Hi Clemens, >> >> I'm not getting any warning. What GCC are you using? > > I am using GCC 7.3.0. > > I think the -Wimplicit-fallthrough warning was introduced with 7.x and > is enabled by -Wextra. > > Regards, > Clemens Indeed. Thanks for spotting that. I applied it to master and v1.0.x. Could you backport this patch to v0.3.x as well? Best regards, Bartosz Golaszewski -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/src/tools/tools-common.c b/src/tools/tools-common.c index 4c138a8..1bc17e2 100644 --- a/src/tools/tools-common.c +++ b/src/tools/tools-common.c @@ -21,14 +21,12 @@ #include <libgen.h> #include <errno.h> -#define NORETURN __attribute__((noreturn)) - const char * get_progname(void) { return program_invocation_name; } -void NORETURN PRINTF(1, 2) die(const char *fmt, ...) +void die(const char *fmt, ...) { va_list va; @@ -41,7 +39,7 @@ void NORETURN PRINTF(1, 2) die(const char *fmt, ...) exit(EXIT_FAILURE); } -void NORETURN PRINTF(1, 2) die_perror(const char *fmt, ...) +void die_perror(const char *fmt, ...) { va_list va; diff --git a/src/tools/tools-common.h b/src/tools/tools-common.h index 0f8e92b..dad18a4 100644 --- a/src/tools/tools-common.h +++ b/src/tools/tools-common.h @@ -19,14 +19,15 @@ * common code. */ +#define NORETURN __attribute__((noreturn)) #define PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg))) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) #define GETOPT_NULL_LONGOPT NULL, 0, NULL, 0 const char * get_progname(void); -void die(const char *fmt, ...); -void die_perror(const char *fmt, ...); +void die(const char *fmt, ...) NORETURN PRINTF(1, 2); +void die_perror(const char *fmt, ...) NORETURN PRINTF(1, 2); void print_version(void); #endif /* __GPIOD_TOOLS_COMMON_H__ */
The attributes should be in the definition in the header file. Otherwise, the noreturn attribute seems to have no effect and GCC emits several Wimplicit-fallthrough warnings when compiling libgpiod. This patch fixes those warnings. Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com> --- src/tools/tools-common.c | 6 ++---- src/tools/tools-common.h | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-)