This is the mail archive of the gcc-prs@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]

c++/3012: c++ bug



>Number:         3012
>Category:       c++
>Synopsis:       templated member function fails within templated class
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu May 31 08:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Robert B. Lowrie
>Release:        3.0 20010528 (prerelease)
>Organization:
>Environment:
System: Linux belle 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-20010528/configure --prefix=/usr/local/gcc-20010528
>Description:
        If a templated member function `foo' of even a non-templated class
`A' is called within a templated class `B' with the syntax
foo<double>(), the compiler gives a syntax error.
>How-To-Repeat:
// Here is a code snippet that repeats the problem:

#include <iostream>

// Defining B_IS_A_TEMPLATE makes class B a template and this code fails
// to compile.   If not defined (comment next line out), the code compiles
// and runs successfully.

#define B_IS_A_TEMPLATE

class A
{
  public:
    
    template <class T>
    void foo() const
    {
	T data;
	std::cout << data << std::endl;
    }
};

#ifdef B_IS_A_TEMPLATE
template <class T>
#endif
class B
{
  public:
    
    void bar(const A& a) const
    {
	// when B is a template, compile fails on this line:
	a.foo<double>();
    }
};

int main()
{
    A a;

#ifdef B_IS_A_TEMPLATE
    B<int> b;
#else
    B b;
#endif

    b.bar(a);
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


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