public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/9380: nested template problem for methods without argument : parsing error
@ 2003-01-20 23:26 picaud.vincent
  0 siblings, 0 replies; 3+ messages in thread
From: picaud.vincent @ 2003-01-20 23:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9380
>Category:       c++
>Synopsis:       nested template problem for methods without argument : parsing error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 20 23:26:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     picaud.vincent@wanadoo.fr
>Release:        gcc 3.2.1
>Organization:
>Environment:
RedHat 7.1, i686 (I have installed the release gcc 3.2.1 without any problem, the original one (RH7.1) was gcc 2.96)
>Description:
Dear GCC Team,

First of all I hope i won't do you waste your time... I use gcc every time in my work and it's a marvelous compiler !

But I think I have found a bug, please consider the short code given in How to Repeat :

When I define a method with no argument, like the method "how_many()" I can't use it in a templated function (or class) like with the function foo_2<>(...)... I get a parsing error (before "(") from the compiler.
The problem doesn't happen with the function foo_1 (which is not templated).

I hope that you will be able to reproduce the problem : for that simply (try to) compile my short example.

Regards,
>How-To-Repeat:
enum topological_dimension {
  Vertex=0,
  Edge=1,
  Face=2,
  Volume=3,
};

template<topological_dimension dim_1>
class A
{
public:
  template<topological_dimension dim_2>
  void how_many() const
  {
  }
};

// This works
// Edge for example: Vertex, Face... give the same result
void foo_1(const A<Edge>& a)
{
  a.how_many<Vertex>();
  // Vertex for example:Edge, Face... give the same result
}

// This doesn't work : compiler error :-( (gcc 3.2.1)
//
template<topological_dimension dim>
void foo_2(const A<dim>& a)
{
  a.how_many<Vertex>(); // <-- Error parsing this line
  // Vertex for example: Edge, Face...give the same result
}

main()
{
}
>Fix:
To avoid the compilation problem, I use the simple following trick :

I introduce an articifial class id_foo<> doing nothing appart being an argument of the function how_many...

enum topological_dimension {
  Vertex=0,
  Edge=1,
  Face=2,
  Volume=3,
};

template<topological_dimension dim_1>
struct id_foo
{
};

template<topological_dimension dim_1>
class A
{
public:
  template<topological_dimension dim_2>
  void how_many(const id_foo<dim_2>& id) const
  {
  }
};

// Now, this works... but it's not really convenient...
//
template<topological_dimension dim>
void foo_2(const A<dim>& a)
{
  a.how_many<Vertex>(id_foo<Vertex>()); // ok...
  a.how_many(id_foo<Vertex>()); // also ok...
}

main()
{
}
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c++/9380: nested template problem for methods without argument : parsing error
@ 2003-01-22 10:56 Vincent PICAUD
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent PICAUD @ 2003-01-22 10:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/9380; it has been noted by GNATS.

From: "Vincent PICAUD" <PICAUD.VINCENT@wanadoo.fr>
To: <lerdsuwa@gcc.gnu.org>,
 <gcc-bugs@gcc.gnu.org>,
 <gcc-prs@gcc.gnu.org>,
 <nobody@gcc.gnu.org>,
 <picaud.vincent@wanadoo.fr>,
 <gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: c++/9380: nested template problem for methods without argument : parsing error  
Date: Wed, 22 Jan 2003 11:51:09 +0100 (MET)

 Thank you very much for your valuable explanations... 
 I apologise for my mistake... I didn't know this C++ syntax : "a.template=
  how_many<Vertex>();"
 Now all work fine and thanks to you I can continue to develop my code.
 Regards,
 
 -- Vincent Picaud.
 
 
 >Messsage du 21/01/2003 14:15
 >De :  <lerdsuwa@gcc.gnu.org>,  <gcc-bugs@gcc.gnu.org>,  <gcc-prs@gcc.gnu=
 .org>,  <nobody@gcc.gnu.org>,  <picaud.vincent@wanadoo.fr>,  <gcc-gnats@gc=
 c.gnu.org>
 >A :  <gcc-bugs@gcc.gnu.org>,  <gcc-prs@gcc.gnu.org>,  <nobody@gcc.gnu.or=
 g>,  <picaud.vincent@wanadoo.fr>
 >Copie =E0 : 
 >Objet : Re: c++/9380: nested template problem for methods without argume=
 nt : parsing error  
 >
 > Synopsis: nested template problem for methods without argument : parsin=
 g error
 > 
 > State-Changed-From-To: open->closed
 > State-Changed-By: lerdsuwa
 > State-Changed-When: Tue Jan 21 14:15:05 2003
 > State-Changed-Why:
 >     Not a bug.  Your code inside 'foo_2':
 >       a.how_many<Vertex>();
 >     'a' depends on the template parameter 'dim' so the compiler
 >     doesn't know if 'how_many' is a variable, a type, or a
 >     template.  For example, you can declare a specialization
 >       template<> class A<Volumn> { int how_many; }
 >     Then 'A<Vertex>.how_many' is a template function but
 >     'A<Volumn>.how_many' is a variable.  
 >     
 >     When you are referring to a template when the context is 
 >     template parameter dependent, you need the 'template' 
 >     keyword as in:
 >       a.template how_many<Vertex>();
 >     The same applies to the example in the Fix section:
 >       a.template how_many<Vertex>(id_foo<Vertex>());
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl=3Fcmd=3Dview%20audit-trail&datab=
 ase=3Dgcc&pr=3D9380
 > 
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c++/9380: nested template problem for methods without argument : parsing error
@ 2003-01-21 14:15 lerdsuwa
  0 siblings, 0 replies; 3+ messages in thread
From: lerdsuwa @ 2003-01-21 14:15 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, picaud.vincent

Synopsis: nested template problem for methods without argument : parsing error

State-Changed-From-To: open->closed
State-Changed-By: lerdsuwa
State-Changed-When: Tue Jan 21 14:15:05 2003
State-Changed-Why:
    Not a bug.  Your code inside 'foo_2':
      a.how_many<Vertex>();
    'a' depends on the template parameter 'dim' so the compiler
    doesn't know if 'how_many' is a variable, a type, or a
    template.  For example, you can declare a specialization
      template<> class A<Volumn> { int how_many; }
    Then 'A<Vertex>.how_many' is a template function but
    'A<Volumn>.how_many' is a variable.  
    
    When you are referring to a template when the context is 
    template parameter dependent, you need the 'template' 
    keyword as in:
      a.template how_many<Vertex>();
    The same applies to the example in the Fix section:
      a.template how_many<Vertex>(id_foo<Vertex>());

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9380


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-01-22 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-20 23:26 c++/9380: nested template problem for methods without argument : parsing error picaud.vincent
2003-01-21 14:15 lerdsuwa
2003-01-22 10:56 Vincent PICAUD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).