From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3891 invoked by alias); 9 Aug 2002 20:46:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3870 invoked by uid 71); 9 Aug 2002 20:46:01 -0000 Resent-Date: 9 Aug 2002 20:46:01 -0000 Resent-Message-ID: <20020809204601.3869.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, Nicolas Noble Received: (qmail 329 invoked from network); 9 Aug 2002 20:37:31 -0000 Received: from unknown (HELO the-babel-tower.nobis-crew.org) (62.212.105.144) by sources.redhat.com with SMTP; 9 Aug 2002 20:37:31 -0000 Received: (qmail 2298 invoked by uid 1000); 9 Aug 2002 20:37:29 -0000 Message-Id: <20020809203729.2297.qmail@the-babel-tower.nobis-crew.org> Date: Fri, 09 Aug 2002 14:06:00 -0000 From: Nicolas Noble To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: 3.113 Subject: c++/7562: strange behaviour with typedef and consts X-SW-Source: 2002-08/txt/msg00200.txt.bz2 List-Id: >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: