[PR44627] templates with class and pointer error cause bailing out and crash

Bug #503668 reported by James Legg
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
gcc
Fix Released
Medium
gcc-4.4 (Ubuntu)
Medium
Unassigned

Bug Description

Binary package hint: gcc-4.4

With this file as the only input:
==============
class A
{
    A * get_a_pointer();
};

template <class T>
void function()
{
    A::get_a_pointer().anything;
}
==============

The g++ crashes with this output:

==============

crashy_test.cpp:9: confused by earlier errors, bailing out
Preprocessed source stored into /tmp/ccWR7fhP.out file, please attach this to your bugreport.
==============

A box pops up with the message "Sorry, the program cc1plus closed unexpectedly". Here is the preprocessed source it saved:

==============
// /usr/lib/gcc/x86_64-linux-gnu/4.4.1/cc1plus -quiet -D_GNU_SOURCE crashy_test.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase crashy_test.cpp -mtune=generic -auxbase crashy_test -fstack-protector -o - -frandom-seed=0
# 1 "crashy_test.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "crashy_test.cpp"
class A
{
    A * get_a_pointer();
};

template <class T>
void function()
{
    A::get_a_pointer().anything;
}
==============

Other info:

It doesn't seem to matter that 'anything' doesn't exist. Replacing it with a member (variable or function) that does exist doesn't make a difference.
You get a similar error even if you remove the last '}'.
This bug should be low priority, since it only occurs if your code has two errors g++ should be reporting (in the second to last line):
-You cannot call A::get_a_pointer() without an object, and
-You cannot request members from the non-class type A*.
I don't mind it reporting one of these errors, then bailing out without crashing.
The problem goes away if you make A::get_a_pointer static, or if you replace the . with ->. It also goes away if you make function not a template function. It can be reproduced if you make function a member function of a templated class instead.

$ g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8)

$ apt-cache policy gcc-4.4
gcc-4.4:
  Installed: 4.4.1-4ubuntu8
  Candidate: 4.4.1-4ubuntu8
  Version table:
 *** 4.4.1-4ubuntu8 0
        500 http://gb.archive.ubuntu.com karmic/main Packages
        100 /var/lib/dpkg/status

$ uname -a
Linux ubuntu 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:02:15 UTC 2009 x86_64 GNU/Linux

$ lsb_release -rd
Description: Ubuntu 9.10
Release: 9.10

Matthias Klose (doko)
summary: - templates with class and pointer error cause bailing out and crash
+ [PR44627] templates with class and pointer error cause bailing out and
+ crash
Changed in gcc-4.4 (Ubuntu):
importance: Undecided → Medium
status: New → Confirmed
Changed in gcc:
status: Unknown → In Progress
Changed in gcc:
status: In Progress → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package gcc-4.4 - 4.4.4-6ubuntu1

---------------
gcc-4.4 (4.4.4-6ubuntu1) maverick; urgency=low

  * Merge with Debian.

gcc-4.4 (4.4.4-6) unstable; urgency=low

  * Update to SVN 20100622 from the gcc-4_4-branch (r161235).
    - Fix PR bootstrap/44544, PR fortran/44536, PR target/44534,
      PR tree-optimization/44508, PR target/44261, PR target/43740,
      PR bootstrap/44426. PR c++/44627 (LP: #503668), PR target/39690.

  [ Matthias Klose ]
  * Add M68K TLS support, backport from the 4.5 branch. Closes: #586060.
  * Merge binary-libgcc.mk packaging changes into binary-libgcc-cross.mk
    (Loic Minier).
  * Fix Fortran cross-compiler build when not building the runtime library.
  * Apply proposed fix for PR target/44626 (backport from the 4.5 branch).
    LP: #564492.
  * Add maintainer scripts for cross packages.

  [ Marcin Juszkiewicz ]
  * Merge the rules.d/binary-*-cross.mk files into rules.d/binary-*.mk.
  * ARM: speed up division on Thumb-2 (backport from the trunk). LP: #589779.

gcc-4.4 (4.4.4-5) unstable; urgency=low

  [ Matthias Klose ]

  * Update to SVN 20100612 from the gcc-4_4-branch (r160657).
    - Fix PR target/44169, PR target/44481, PR target/44075, PR other/43838,
      PR libstdc++/32499, PR libgcj/44216.
  * debian/patches/libstdc++-pic.diff: Fix installation for cross builds.
  * Update libsupc++/vmi_class_type_info.cc from the 4.5 branch.
    Closes: #584308.
  * Export long double versions of "C" math library for arm-linux-gnueabi,
    m68k-linux-gnu (ColdFire), mips*-linux-gnu (o32 ABI), sh*-linux-gnu
    (not 32 bit). Merge the libstdc++-*-ldbl-compat.diff patches.
  * Remove the backport for the plugin support.

  [ Aurelien Jarno ]
  * libstdc++-mips-ldbl-compat.diff: On MIPS provide the long double
    versions of "C" math functions in libstdc++ as we need to keep the
    ABI. Closes: #584610.
 -- Matthias Klose <email address hidden> Fri, 25 Jun 2010 15:04:36 +0200

Changed in gcc-4.4 (Ubuntu):
status: Confirmed → Fix Released
Changed in gcc:
importance: Unknown → Medium
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.