Skip to content

configure.ac: compile with -Wdeclaration-after-statement#328

Closed
kdudka wants to merge 2 commits intologrotate:masterfrom
kdudka:c90
Closed

configure.ac: compile with -Wdeclaration-after-statement#328
kdudka wants to merge 2 commits intologrotate:masterfrom
kdudka:c90

Conversation

@kdudka
Copy link
Member

@kdudka kdudka commented Jun 1, 2020

... to make sure we keep the code ISO C90 compliant

@kdudka kdudka changed the title configure.ac: compile with -Wdeclaration-after-statement configure.ac: compile with -Wdeclaration-after-statement Jun 1, 2020
@cgzones
Copy link
Member

cgzones commented Jun 2, 2020

I think the current code is not quite ISO C90 compliant.
clang -Weverything -std=c90 shows:

  CC       config.o
In file included from config.c:29:
./logrotate.h:86:5: warning: empty macro arguments are a C99 feature [-Wc99-extensions]
    TAILQ_ENTRY(logInfo) list;
    ^
./queue.h:382:52: note: expanded from macro 'TAILQ_ENTRY'
#define TAILQ_ENTRY(type)       _TAILQ_ENTRY(struct type,)
                                                         ^
In file included from config.c:29:
./logrotate.h:89:1: warning: empty macro arguments are a C99 feature [-Wc99-extensions]
TAILQ_HEAD(logInfoHead, logInfo);
^
./queue.h:372:62: note: expanded from macro 'TAILQ_HEAD'
#define TAILQ_HEAD(name, type)  _TAILQ_HEAD(name, struct type,)
                                                              ^
config.c:123:21: warning: commas at the end of enumerator lists are a C99-specific feature [-Wc99-extensions]
    STATE_ERROR = 64,
                    ^
config.c:733:9: warning: designated initializers are a C99 feature [-Wc99-designator]
        .pattern = NULL,
        ^
config.c:934:9: warning: designated initializers are a C99 feature [-Wc99-designator]
        .l_start = 0,
        ^
5 warnings generated.
  CC       log.o
  CC       logrotate.o
In file included from logrotate.c:31:
./logrotate.h:86:5: warning: empty macro arguments are a C99 feature [-Wc99-extensions]
    TAILQ_ENTRY(logInfo) list;
    ^
./queue.h:382:52: note: expanded from macro 'TAILQ_ENTRY'
#define TAILQ_ENTRY(type)       _TAILQ_ENTRY(struct type,)
                                                         ^
In file included from logrotate.c:31:
./logrotate.h:89:1: warning: empty macro arguments are a C99 feature [-Wc99-extensions]
TAILQ_HEAD(logInfoHead, logInfo);
^
./queue.h:372:62: note: expanded from macro 'TAILQ_HEAD'
#define TAILQ_HEAD(name, type)  _TAILQ_HEAD(name, struct type,)
                                                              ^
logrotate.c:908:42: warning: initializer for aggregate is not a compile-time constant [-Wc99-extensions]
    char * const mailArgv[] = { (char *) mailComm, (char *) "-s", (char *) subject, (char *) address, NULL };
                                         ^~~~~~~~
logrotate.c:2927:27: warning: initializer for aggregate is not a compile-time constant [-Wc99-extensions]
        {"force", 'f', 0, &force, 0, "Force file rotation", NULL},
                          ^~~~~~
4 warnings generated.
  CCLD     logrotate

and gcc-10 -std=c90 -Wpedantic shows:

[...]
log.h:24:67: warning: ISO C90 does not support ‘__func__’ predefined identifier [-Wpedantic]
   24 |         message(MESS_ERROR, "cannot allocate memory [%s():%d]\n", __func__, __LINE__); \
      |                                                                   ^~~~~~~~
config.c:172:9: note: in expansion of macro ‘message_OOM’
  172 |         message_OOM();
      |         ^~~~~~~~~~~
[...]
logrotate.c:2222:37: warning: ISO C90 does not support the ‘j’ gnu_printf length modifier [-Wformat=]
 2222 |                 message(MESS_DEBUG, "after %jd days ", (intmax_t)log->threshold);
      |                                     ^~~~~~~~~~~~~~~~~
logrotate.c:2234:37: warning: ISO C90 does not support the ‘j’ gnu_printf length modifier [-Wformat=]
 2234 |                 message(MESS_DEBUG, "%jd bytes ", (intmax_t)log->threshold);
      |                                     ^~~~~~~~~~~~
logrotate.c:2256:29: warning: ISO C90 does not support the ‘j’ gnu_printf length modifier [-Wformat=]
 2256 |         message(MESS_DEBUG, "only log files >= %jd bytes are rotated, ", (intmax_t)log->minsize);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
logrotate.c:2259:29: warning: ISO C90 does not support the ‘j’ gnu_printf length modifier [-Wformat=]
 2259 |         message(MESS_DEBUG, "log files >= %jd are rotated earlier, ", (intmax_t)log->maxsize);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[...]

@kdudka
Copy link
Member Author

kdudka commented Jun 5, 2020

Good point. On the other hand, nobody has complained about these warnings for a couple of releases. Are you suggesting to reword the commit message or rather drop this completely?

@cgzones
Copy link
Member

cgzones commented Jun 5, 2020

I am fine with the commits, just wanted to make sure there are no wrong expectations.

@kdudka
Copy link
Member Author

kdudka commented Jun 5, 2020

I see it is not perfect but it can still be useful in some cases, so merging it. Thanks for review!

@kdudka kdudka closed this in 25bcd56 Jun 5, 2020
@kdudka kdudka deleted the c90 branch June 5, 2020 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants