c++/4272: gcc 3.0 (g++) crash related to namespaces and erroneously passing things like std::less() without the ().

Steven Brown swbrown@ucsd.edu
Sun Sep 9 01:56:00 GMT 2001


>Number:         4272
>Category:       c++
>Synopsis:       g++ can be made to segfault trying to compile code that incorrectly uses a templated struct as an expression when using namespaces in a certain way.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-illegal-code
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 09 01:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Steven Brown
>Release:        3.0
>Organization:
>Environment:
System: Linux depraved.depraved.org 2.4.3-12 #1 Fri Jun 8 15:05:56 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --prefix=/home/swbrown/gcc-3.0
>Description:
	I ran into this passing std::less into a function like find_if.  I
	omitted the ()'s on std::less when passing it and it crashed g++.  I
	wrote up a test case and the crash seems related to namespaces.  If you
	use a 'using namespace' line to bring the definition in and skip the
	direct notation like std::, it would give an error instead of crashing.
	CodeSourcery's online test compiler crashes with it as well.  The code
	included is a simplification of the problem that will cause the crash.
>How-To-Repeat:

	Compile this like "g++ whatever.cc":

		namespace foo {
			template<typename T>
			struct fooStruct {};
		}

		template<typename T> void fooFunc(T) {}

		//using namespace foo;

		int main() {
			fooFunc(foo::fooStruct);
			//fooFunc(fooStruct);
		}

	g++ will spit out a segfault.  Now try it using the namespace method -
	uncomment the two lines I commented and comment out the original
	fooFunc call.  Instead of crashing, it will say:

		xx.cc: In function `int main()':
		xx.cc:12: use of class template `template<T> struct
		foo::fooStruct' as expression
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list