public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: picaud.vincent@wanadoo.fr
To: gcc-gnats@gcc.gnu.org
Subject: c++/9380: nested template problem for methods without argument : parsing error
Date: Mon, 20 Jan 2003 23:26:00 -0000	[thread overview]
Message-ID: <20030120231931.7111.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2003-01-20 23:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-20 23:26 picaud.vincent [this message]
2003-01-21 14:15 lerdsuwa
2003-01-22 10:56 Vincent PICAUD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030120231931.7111.qmail@sources.redhat.com \
    --to=picaud.vincent@wanadoo.fr \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).