Bug 29830 - Name lookup bug for inner template specialization
Summary: Name lookup bug for inner template specialization
Status: RESOLVED DUPLICATE of bug 14032
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-14 12:48 UTC by Zoltan Jasz
Modified: 2006-11-14 16:30 UTC (History)
6 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: 4.1.1 20060525 (Red Hat 4.1.1-1)
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zoltan Jasz 2006-11-14 12:48:30 UTC
Hi,

I haven't found any related bug in the known bugs database.
Also I posted this problem to several forums to be shore that this code doesn't violate the C++ standard. ~60% replies that this should work. Moreover two other compilers can compile without any problem:

The simplified code:
//////////////////////////////////
#include <stdio.h>
template <typename T, int v> class record_descriptor {
public:
     void operator()()
     {
         printf("Global template\n");
     }
};
template<typename T, int v, template<typename,int> class RD =
record_descriptor> class TableRecord {
public:
     TableRecord()
     {
         RD<T, v> d;
         d();
     }
};
template<typename A> class Attr
{
public:
     template <typename T, int v> class i_record_descriptor
     {
     };
     template <int v> class i_record_descriptor<A, v>
     {
     public:
         void operator()()
         {
             printf("Inner spec template\n");
         }
     };
     Attr()
     {
         TableRecord<A, 1, i_record_descriptor> tr;
     }
};
int main()
{
     Attr<int> attr;
     return 0;
}
//////////////////////////////
Message:
gccbug.cpp: In constructor 'TableRecord<T, v, RD>::TableRecord() [with T = int, int v = 1, RD = Attr<int>::i_record_descriptor]':
gccbug.cpp:32:   instantiated from 'Attr<A>::Attr() [with A = int]'
gccbug.cpp:37:   instantiated from here
gccbug.cpp:15: error: no match for call to '(Attr<int>::i_record_descriptor<int, 1>) ()'
--------------------------------------------------------
If i_class_descriptor template has an implementation:
//////////////////////////////////////////////////////
#include <stdio.h>
template <typename T, int v> class record_descriptor {
public:
     void operator()()
     {
         printf("Global template\n");
     }
};
template<typename T, int v, template<typename,int> class RD =
record_descriptor> class TableRecord {
public:
     TableRecord()
     {
         RD<T, v> d;
         d();
     }
};
template<typename A> class Attr
{
public:
     template <typename T, int v> class i_record_descriptor
     {
     public:
         void operator()()
         {
             printf("Inner template\n");
         }
     };
     template <int v> class i_record_descriptor<A, v>
     {
     public:
         void operator()()
         {
             printf("Inner spec template\n");
         }
     };
     Attr()
     {
         TableRecord<A, 1, i_record_descriptor> tr;
     }
};
int main()
{
     Attr<int> attr;
     return 0;
}
/////////////////////////////////////////////////////
...compiles but the result after executing is "Inner template" instead of "Inner spec template"

If the parameter 'A' is changed in the partial specialozation to a primitve type, ex: 'int' then compiles fine and the result is correct.

The last version I tried was:
g++ (GCC) 4.1.2 20060901 (prerelease) (Debian 4.1.1-13)

I hope I give you all the necessary information!

Regards,
Zoltan Jasz

Software developer,
Ericsson Telecomunication Hungary Ltd.
Comment 1 Pawel Sikora 2006-11-14 12:53:35 UTC
this is a dup of PR29767
Comment 2 Zoltan Jasz 2006-11-14 15:02:19 UTC
(In reply to comment #1)
> this is a dup of PR29767

Sorry for duplication, I haven't checked again after I posted to the gcc-help.
Comment 3 Andrew Pinski 2006-11-14 16:30:52 UTC

*** This bug has been marked as a duplicate of 14032 ***