This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/27693] New: strange interaction with const and sizeof and variable declarations in g++-4.0
- From: "markghayden at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 May 2006 22:49:21 -0000
- Subject: [Bug c++/27693] New: strange interaction with const and sizeof and variable declarations in g++-4.0
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I don't know how to describe this. The compiler generates a warning in a very
specific case. See the very simple and small program below and the different
cases where the type error occurs and doesn't occur. I'm not a C++ expert but
this seems whacky. Note that this does not occur with gcc on any version. It
doesn't occur with earlier (g++-3.4) versions of g++. It does occur in
g++-4.1. BTW, the compileres I've tested in on are all from from a machine
running up-to-date Debian 'test'.
cheers, Mark
cd /home/mhayden/spool/
make -k
g++-4.0 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
cat a.c
typedef struct _a_t {
int b ;
} * a_t ;
extern a_t c(int) ;
int main() {
a_t const a0 = c(0) ;
a_t a1 = c(sizeof(*a1)) ;
a_t const a2 = c(sizeof(*a2)) ;
a_t const a3 = c(sizeof(*a2)) ;
a_t const a4 = c(sizeof(*a0)) ;
a0->b = 0 ; /* ok */
a1->b = 0 ; /* ok */
a2->b = 0 ; /* not ok */
a3->b = 0 ; /* not ok */
a4->b = 0 ; /* ok */
return 0 ;
}
g++-4.0 -c a.c
a.c: In function 'int main()':
a.c:15: error: base operand of '->' is not a pointer
a.c:16: error: base operand of '->' is not a pointer
make: *** [a.o] Error 1
Compilation exited abnormally with code 2 at Sat May 20 15:41:55
--
Summary: strange interaction with const and sizeof and variable
declarations in g++-4.0
Product: gcc
Version: 4.0.4
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: markghayden at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27693