Bug 37087

Summary: Segfault on compiling template defined in wrong namespace.
Product: gcc Reporter: kenton <kenton>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: bangerth, gcc-bugs
Priority: P3 Keywords: ice-on-invalid-code
Version: 4.0.3   
Target Milestone: 4.4.0   
Host: i486-pc-linux-gnu Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu Known to work: 4.4.0
Known to fail: 4.3.1 Last reconfirmed: 2008-08-11 22:41:51

Description kenton@google.com 2008-08-11 22:23:39 UTC
G++ reports a segmentation fault when compiling the code below.

Environment:
System: Linux temporal.corp.google.com 2.6.18.5-gg34workstation-mixed64-32 #1 SMP Thu May 8 01:31:23 UTC 2008 x86_64 GNU/Linux
Architecture: x86_64

host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-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=pentium4 --enable-checking=release i486-linux-gnu

How-To-Repeat:
Invoke g++ on the following (invalid) code with no other arguments.
There are no #includes; this is the entire source file.

======================
namespace a {
  template <typename T> class Foo;
}

namespace b {
  template <> class ::a::Foo<double> {};
}
======================

(The gccbug script claims it will remove "comments" delimited by angle brackets.
Hopefully that isn't actually true because it will mess up the above code
sample as well as the following error log.)

Result:
testtemplate.cc:6: error: global qualification of class name is invalid before '{' token
testtemplate.cc:6: error: specialization of 'template<class T> struct a::Foo' in different namespace
testtemplate.cc:2: error:   from definition of 'template<class T> struct a::Foo'
g++: Internal error: Segmentation fault (program cc1plus)
Please submit a full bug report.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions, see
<URL:file:///usr/share/doc/gcc-4.0/README.Bugs>.
Comment 1 kenton@google.com 2008-08-11 22:23:39 UTC
Fix:
Unknown.
Comment 2 paolo@gcc.gnu.org 2008-08-12 19:39:26 UTC
Subject: Bug 37087

Author: paolo
Date: Tue Aug 12 19:38:02 2008
New Revision: 139034

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139034
Log:
/cp
2008-08-12  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/37087
	* parser.c (cp_parser_class_head): Early return error_mark_node in
	case of global qualification of class name or qualified name that
	does not name a class.

/testsuite
2008-08-12  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/37087
	* g++.dg/template/crash80.C: New.
	* g++.old-deja/g++.other/decl5.C: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/template/crash80.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.old-deja/g++.other/decl5.C

Comment 3 Paolo Carlini 2008-08-12 19:45:39 UTC
Fixed for 4.4.0.
Comment 4 Wolfgang Bangerth 2008-08-13 16:24:54 UTC
This also failed with 4.2.1, and the reporter's compiler was 4.0.

Paolo, do you want to apply your patch to 4.3.x as well? If not,
I vote for closing the PR: It's not a recent regression, it's an
ICE on invalid, and unless you apply the patch there is unlikely
going to be any further activity.

W.
Comment 5 Paolo Carlini 2008-08-13 16:29:01 UTC
Let's close it, as you say it's invalid code, not a regression.