public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/7562: strange behaviour with typedef and consts
@ 2002-08-09 14:16 Graham Stott
  0 siblings, 0 replies; 4+ messages in thread
From: Graham Stott @ 2002-08-09 14:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7562; it has been noted by GNATS.

From: Graham Stott <graham.stott@btinternet.com>
To: Nicolas Noble <nicolas@nobis-crew.org>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7562: strange behaviour with typedef and consts
Date: Fri, 09 Aug 2002 21:56:20 +0100

 Nicolas Noble wrote:
 
 > Here is the simple source code:
 > 
 > $ cat typedef.cc 
 > typedef void * voidp;
 > 
 > void func1(const voidp p) { }
 > 
 > void func2(const void * p) {
 >     func1(p);
 > }
 > 
 Not a bug.
 
 The compiler is correct func1 takes "const ptr" where as
 func2 takes a "ptr to a const" thus passing p to func1
 discards the const qualifier from p.
 
 
 
 
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/7562: strange behaviour with typedef and consts
@ 2002-08-09 14:51 Nicolas Noble
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Noble @ 2002-08-09 14:51 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7562; it has been noted by GNATS.

From: Nicolas Noble <Pixel@the-babel-tower.nobis-crew.org>
To: Geoff Keating <geoffk@geoffk.org>
Cc: Nicolas Noble <nicolas@nobis-crew.org>,  <gcc-gnats@gcc.gnu.org>
Subject: Re: c++/7562: strange behaviour with typedef and consts
Date: Fri, 9 Aug 2002 23:15:16 +0200 (CEST)

 > Nicolas Noble <nicolas@nobis-crew.org> writes:
 >
 > > typedef void * voidp;
 > >
 > > void func1(const voidp p) { }
 > >
 > > void func2(const void * p) {
 > >     func1(p);
 > > }
 >
 > 'const voidp p' is the same as 'void * const p', not 'const void * p'.
 > It is correct for the compiler to complain here.
 
 Yeah, I understand perfectly... even if said like that it *IS* clear, I
 was confused by the zlib.h header. I'll complain to Jean-Loup Gailly then
 to correct his code :-)
 
 Thanks a lot!
 
   -- Nicolas Noble
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/7562: strange behaviour with typedef and consts
@ 2002-08-09 14:16 Geoff Keating
  0 siblings, 0 replies; 4+ messages in thread
From: Geoff Keating @ 2002-08-09 14:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7562; it has been noted by GNATS.

From: Geoff Keating <geoffk@geoffk.org>
To: Nicolas Noble <nicolas@nobis-crew.org>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7562: strange behaviour with typedef and consts
Date: 09 Aug 2002 14:12:42 -0700

 Nicolas Noble <nicolas@nobis-crew.org> writes:
 
 > typedef void * voidp;
 > 
 > void func1(const voidp p) { }
 > 
 > void func2(const void * p) {
 >     func1(p);
 > }
 
 'const voidp p' is the same as 'void * const p', not 'const void * p'.
 It is correct for the compiler to complain here.
 
 -- 
 - Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++/7562: strange behaviour with typedef and consts
@ 2002-08-09 14:06 Nicolas Noble
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Noble @ 2002-08-09 14:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7562
>Category:       c++
>Synopsis:       const with typedefs doesn't work as expected.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 09 13:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.1
>Organization:
>Environment:
System: Linux the-babel-tower 2.4.18 #2 Sun Apr 28 23:46:35 CEST 2002 i686 unknown
Architecture: i686

	
host: i386-slackware-linux-gnu
build: i386-slackware-linux-gnu
target: i386-slackware-linux-gnu
configured with: ../gcc-3.1/configure --prefix=/usr --enable-shared --with-gnu-ld --enable-threads --verbose --target=i386-slackware-linux --host=i386-slackware-linux
>Description:
Here is a problem I saw first with the zlib header. It's very easy to understand, I think you'll be able to understand
with the How-To-Repeat section. In brief, it's when having a "const" with a previously typedef'ed type, the compiler
forgets the "const", which only produces a warning in C compilation mode, but produces an error in C++ compilation mode.
>How-To-Repeat:
Here is the simple source code:

$ cat typedef.cc 
typedef void * voidp;

void func1(const voidp p) { }

void func2(const void * p) {
    func1(p);
}

and what happen:

$ gcc-3.1 -c typedef.cc 
typedef.cc: In function `void func2(const void*)':
typedef.cc:6: invalid conversion from `const void*' to `void*'

which is the worse case I think. With a .c extension it only does that:
$ gcc-3.1 -c typedef.c  
typedef.c: In function `func2':
typedef.c:6: warning: passing arg 1 of `func1' discards qualifiers from pointer target type


>Fix:
Actually the only "fix" I was able to think of was to forget typedef'ing the voidp, but this is a pain with the zlib.h
since it has "voidp" everywhere. Another solution, but very ugly, is to #define voidp void * for example.

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-09 21:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-09 14:16 c++/7562: strange behaviour with typedef and consts Graham Stott
  -- strict thread matches above, loose matches on Subject: below --
2002-08-09 14:51 Nicolas Noble
2002-08-09 14:16 Geoff Keating
2002-08-09 14:06 Nicolas Noble

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).