This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bug or my mistake?


Hi, I'm doing some work that'd depend on constructs like this working:

template<class T>
struct foo {
	enum { foo_value = 1 };
	
	struct bar {
		enum { bar_value = 1 };
	};		

	template<class U>
	struct baz {
		enum { baz_value = 1 };
	};
};

//
// TRY_ONE, TRY_TWO, and TRY_FOUR compile fine.
// TRY_THREE Gives:
//  In function `int func()':
// 34: error: expected primary-expression
// 34: error: `::baz_value' has not been declared
//  In function `int func() [with T = param1, U = param2]':
// 43:   instantiated from here
// 34: error: `foo<T>::baz' names a type, but a non-type is expected

template<class T, class U>
int func() {
#ifdef TRY_ONE
	return foo<T>::foo_value;	  // Line (1)
#endif
#ifdef TRY_TWO
	return foo<T>::bar::bar_value;    // Line (2)
#endif
#ifdef TRY_THREE
	return foo<T>::baz<U>::baz_value; // Line (3)
#endif
}

struct param1 {};
struct param2 {};

int main() {
#ifndef TRY_FOUR
	return func<param1, param2>();
#endif
#ifdef TRY_FOUR
	return foo<param1>::baz<param2>::baz_value;
#endif
}

with mainline CVS g++, g++ -DTRY_ONE, g++ -DTRY_TWO, and g++ -DTRY_FOUR work fine,
but -DTRY_THREE gives the errors listed above.


Am I attempting to do something not permitted in C++, or is this just a parser bug?
I spent a couple days in gdb tracking down what happens, so if this is a bug, then
I've got a decent idea of where to start fixing it. Due to the importance of the
issue to me, I'm more than prepared to go in and fix it myself, but I don't want
to tread on anyone's feet. Is it better to just submit a bug report?


Thanks
-ls

-- To starve to death is a small thing, but to lose one's integrity is a great one.
- Chinese Proverb.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]