[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#39071: libc6-dev: ctype.h contains "-pedantic -O" warning



Package: libc6-dev
Version: 2.1.1-10

Consider: 
  $ cat toupper.c
  #include <stdio.h>
  #include <ctype.h>
  int main(void) {
    char c;
    c = toupper('a');
    printf("toupper('a') = '%c'\n", c);
    return 0;
  }
  $ gcc -pedantic -O toupper.c
  toupper.c: In function `main':
  toupper.c:5: warning: ANSI C forbids braced-groups within expressions
  $

This warning here is new with libc6 2.1.

Other header files use __extension__ before braced-groups within
expressions, so here is a patch for ctype.h to suppress the warning.

------------------------------ 8< ------------------------------
--- /usr/include/ctype.h.orig   Mon May 31 06:18:37 1999
+++ /usr/include/ctype.h        Sun Jun  6 17:18:23 1999
@@ -165,6 +165,7 @@
 
 #if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
 # define __tobody(c, f, a) \
+  __extension__                                                         \
   ({ int __res;                                                         \
      if (sizeof (c) > 1)                                                \
        {                                                                \
------------------------------ >8 ------------------------------

[I you really want to patch this, use -l since I messed with the
 whitespace to make it fit.]

Even pedants should be able to optimize calls to toupper().

Kirk Hilliard


P.S.  Here is another warning that is new for libc6 2.1.

  $ cat strcmp.c 
  #include<string.h>
  int main(void) {
    void *v = "Hello, world.";
    strcmp(v,v);
    return 0;
  }
  $ gcc -Wpointer-arith -O strcmp.c 
  strcmp.c: In function `main':
  strcmp.c:4: warning: pointer of type `void *' used in arithmetic
  strcmp.c:4: warning: pointer of type `void *' used in arithmetic
  strcmp.c:4: warning: pointer of type `void *' used in arithmetic
  strcmp.c:4: warning: pointer of type `void *' used in arithmetic
  strcmp.c:4: warning: pointer of type `void *' used in arithmetic
  strcmp.c:4: warning: pointer of type `void *' used in arithmetic
  $

At first this one did not bother me because it can be easily fixed by
explicitly casting the arguments of strcmp() to (string *).  But the
warning doesn't say a thing about implicit casting.  (Nor do -Wall or
-pedantic (or a slew of other warnings the upstream maintainer likes
to use) complain about the implicit casting.)

The source of the warning is in /usr/include/bits/string2.h:

  #define __string2_1bptr_p(__x) \
    ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1)
                            ^^^^^^^^^

I think that ``__extension__'' only works with -pedantic -- at least I
couldn't get it to work its magic here.  I don't know how to fix this.
Is it even worthy of being fixed?


Reply to: