On the following code:

#ifndef NOINLINES
#define EINLINE __inline__
#else
#define EINLINE
#endif

EINLINE int a(void *value)
{
  return *(char *)value;
}

int b(const char *val)
{
  return a((char *)val);
}

int c(void)
{
  return b("whatever");
}

... compiling it with these flags: -W -Wall -Winline -Wshadow -Werror -O
... gives this warning (treated as an error as requested):

pqp.c: In function ‘b’:
pqp.c:16: warning: passing argument 1 of ‘a’ discards qualifiers from pointer
target type

if you pass -DNOINLINES on the command line, i.e. take away the inline
attribute, this goes away, except if I compile with -O3 (which tries to inline
it anyway). Please note the explicit cast to (char *) at a; without that cast
gcc should (and it does) warn both with and without attribute inline, but I
couldn't find a way to make the explicit cast respected when gcc is inlining
functions.

I couldn't reproduce this on gcc 4.1.x, i.e. it behaves ok.


-- 
           Summary: inline attribute seems to mess with const qualifier.
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexandre dot nunes at gmail dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34076

Reply via email to