Bug 19487 - [3.3 Regression] map with a class template + method template fails to compile.
Summary: [3.3 Regression] map with a class template + method template fails to compile.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 3.4.3
Assignee: Not yet assigned to anyone
URL:
Keywords: monitored, rejects-valid
Depends on: 14494
Blocks:
  Show dependency treegraph
 
Reported: 2005-01-17 17:34 UTC by douze
Modified: 2005-04-30 15:08 UTC (History)
4 users (show)

See Also:
Host: 686-pc-linux-gnu
Target:
Build:
Known to work: 3.0.4
Known to fail: 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2005-02-26 18:42:55


Attachments
code that fails (143 bytes, text/plain)
2005-01-17 17:36 UTC, douze
Details

Note You need to log in before you can comment on or make changes to this bug.
Description douze 2005-01-17 17:34:43 UTC
The error message is :

/local_scratch/douze/gcc_cur/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/cpp_type_traits.h:
In instantiation of 'std::__is_pod<std::less<int> >':
/local_scratch/douze/gcc_cur/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_tree.h:431:
  instantiated from 'std::_Rb_tree<int, std::pair<const int, A<0> >,
std::_Select1st<std::pair<const int, A<0> > >, std::less<int>,
std::allocator<std::pair<const int, A<0> > > >'
/local_scratch/douze/gcc_cur/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_map.h:124:
  instantiated from 'std::map<int, A<0>, std::less<int>,
std::allocator<std::pair<const int, A<0> > > >'
test7.cpp:5:   instantiated from 'A<0>'
test7.cpp:10:   instantiated from here
/local_scratch/douze/gcc_cur/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/cpp_type_traits.h:398:
error: too many template parameter lists in declaration of
'std::__is_pod<std::less<int> >::<anonymous enum>'

The error appears with gcc 3.4.1 and gcc 4.0.0, but not with 3.3.2
Comment 1 douze 2005-01-17 17:36:43 UTC
Created attachment 7973 [details]
code that fails

This code fails. Changing about anything in the code makes it work.

The code compiles fine with intel's compiler.
Comment 2 Andrew Pinski 2005-01-17 18:57:55 UTC
I think this is a C++ front-end problem but I would need to reduce the failure.
Also just a note the preprocessed from 3.4.0/4.0.0 is rejected for the same reason in 3.3.3 but 
accepted in 3.0.4.
Comment 3 Paolo Carlini 2005-01-17 19:02:00 UTC
Indeed, Andrew, it's *very* unlikely that this is libstdc++-v3 bug: I see a crazy
error message about __is_pod, which is actually instantiated with the default
std::less...
Comment 4 Andrew Pinski 2005-01-17 19:16:07 UTC
This is definitely a front-end issue, I have the reduced testcase down to about 60 lines, I want to reduce 
it a little further before posting.
Comment 5 Andrew Pinski 2005-01-17 19:16:50 UTC
: Search converges between 2002-10-04-trunk (#94) and 2002-10-05-trunk (#95).
Comment 6 Andrew Pinski 2005-01-17 19:25:39 UTC
Reduced testcase:
template<typename _Tp> struct __is_pod
{
  enum  {  _M_type };
};
template <typename _Key> struct map
{
  static const bool _Is_pod_comparator = __is_pod<_Key >::_M_type;
};
template <int a> struct A {
  static map<int> Cache;
  template <typename B> void f(B out);
};
template <> template <typename B>
void A <0> ::f ( B out) { }
Comment 7 Andrew Pinski 2005-01-17 19:27:36 UTC
One more note, libstdc++ headers changed to exposed this bug in the C++ front-end :(.
Comment 8 Paolo Carlini 2005-01-17 20:01:11 UTC
... if the c++ fe bug cannot be fixed in time for 4.0, we can consider reverting
the library change, which (at variance with the version in v7-branch) is not
really useful in the present form.
Comment 9 Wolfgang Bangerth 2005-01-18 02:36:39 UTC
I'm surprised this is something that hasn't been found yet by one of our 
users. I'd vote to up its importance, it's a rejects-valid of the nasty 
kind since it's going to be almost impossible to work around it... 
 
W. 
Comment 10 Volker Reichelt 2005-01-18 15:16:06 UTC
Further reduced testcase:

==================================================
template<int> struct A
{
    enum { e };
    template<int> void foo();
};

template<> template<int> void A<0>::foo() {}
==================================================

This is probably the same underlying problem as in PR14494.
PR14494 can be reduced to

==================================================
template<int> struct A
{
    template<int> void foo();
};

template<> template<int N> void A<0>::foo<N>() {}
==================================================

which results in the following bogus error message:

PR14494A.cc:10: error: function template partial specialization 'foo<N>' is not
allowed
PR14494A.cc:10: error: no 'void A<0>::foo()' member function declared in class
'A<0>'
PR14494A.cc:10: error: invalid function declaration

A similar version is the following:

==================================================
template<int> struct A
{
    template<int> void foo();
};

template<> template<int> void A<0>::foo() {}
==================================================

which results in the following bogus error message:

PR14494B.cc:10: error: template-id 'foo<>' for 'void A<0>::foo()' does not match
any template declaration
PR14494B.cc:10: error: invalid function declaration

Btw, the underlying problem is not a regression.
Comment 11 Kriang Lerdsuwanakij 2005-01-18 15:21:14 UTC
Related to PR14479.
Comment 12 Kriang Lerdsuwanakij 2005-01-21 16:04:20 UTC
Patch for 3.4 and 4.0 submitted:
  http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01491.html
Comment 13 GCC Commits 2005-02-12 15:40:48 UTC
Subject: Bug 19487

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	lerdsuwa@gcc.gnu.org	2005-02-12 15:40:29

Modified files:
	gcc/cp         : ChangeLog cp-tree.h name-lookup.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: enum5.C 

Log message:
	PR c++/14479
	PR c++/19487
	* pt.c (maybe_check_template_type): Remove.
	* cp-tree.h (maybe_check_template_type): Remove prototype.
	* name-lookup.c (maybe_process_template_type_declaration): Don't
	use maybe_check_template_type.
	
	* g++.dg/template/enum5.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4624&r2=1.4625
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1103&r2=1.1104
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.108&r2=1.109
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.975&r2=1.976
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5025&r2=1.5026
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 15 Kriang Lerdsuwanakij 2005-02-12 16:32:59 UTC
Fixed in 3.4/4.0.
Comment 16 Kriang Lerdsuwanakij 2005-02-12 16:34:37 UTC
Probably won't fixed in 3.3.
Comment 17 Gabriel Dos Reis 2005-04-30 13:19:29 UTC
won't fix for 3.3.6.  Fixed in 3.4.x
Comment 18 Andrew Pinski 2005-04-30 15:08:15 UTC
Fixed so closing as such.