public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32408]  New: Template Parsing Error
@ 2007-06-19 20:22 chsalvia at gmail dot com
  2007-06-19 21:22 ` [Bug c++/32408] " schwab at suse dot de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: chsalvia at gmail dot com @ 2007-06-19 20:22 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1588 bytes --]

GCC may have a defective template parsing routine which seems to mistake the
'<' token in an expression for the beginning of a template argument.  The error
only seems to happen when a templated function evaluates a member of a
templated class or struct with a '<' symbol.

Here is a simple code snippet that reproduces the problem:

template <class T>
struct templated_struct 
{
        int count;
};

template <class T>
int template_func()
{
        templated_struct<T> s;
        if (s.count < 0) return 0;
        return 0;
}

int main()
{
        template_func<int> ();
        return 0;
}

The compiler generates the follow error message when trying to compile the
above code:

test4.cc: In function ‘int template_func()’:
test4.cc:16: error: parse error in template argument list
test4.cc: In function ‘int template_func() [with T = int]’:
test4.cc:22:   instantiated from here
test4.cc:16: error: ‘count’ is not a member template function

Note that the above code compiles just fine if you replace the '<' token in the
IF statement with an '>' or an '==', thus demonstrating that GCC seems to be
confusing the '<' token for a template argument.

A temporary workaround is to put a set of parenthesis around s.count.


-- 
           Summary: Template Parsing Error
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chsalvia at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32408


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

* [Bug c++/32408] Template Parsing Error
  2007-06-19 20:22 [Bug c++/32408] New: Template Parsing Error chsalvia at gmail dot com
@ 2007-06-19 21:22 ` schwab at suse dot de
  2007-06-19 22:04 ` pcarlini at suse dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: schwab at suse dot de @ 2007-06-19 21:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2007-06-19 21:22 -------
*** Bug 32409 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32408


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

* [Bug c++/32408] Template Parsing Error
  2007-06-19 20:22 [Bug c++/32408] New: Template Parsing Error chsalvia at gmail dot com
  2007-06-19 21:22 ` [Bug c++/32408] " schwab at suse dot de
@ 2007-06-19 22:04 ` pcarlini at suse dot de
  2007-06-19 23:08 ` chsalvia at gmail dot com
  2007-06-19 23:10 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pcarlini at suse dot de @ 2007-06-19 22:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pcarlini at suse dot de  2007-06-19 22:04 -------
Apparently you provided the wrong snippet, this one compiles just fine and
well, doesn't have 22 lines... ;)


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32408


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

* [Bug c++/32408] Template Parsing Error
  2007-06-19 20:22 [Bug c++/32408] New: Template Parsing Error chsalvia at gmail dot com
  2007-06-19 21:22 ` [Bug c++/32408] " schwab at suse dot de
  2007-06-19 22:04 ` pcarlini at suse dot de
@ 2007-06-19 23:08 ` chsalvia at gmail dot com
  2007-06-19 23:10 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: chsalvia at gmail dot com @ 2007-06-19 23:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from chsalvia at gmail dot com  2007-06-19 23:08 -------
Sorry.  It seems this is actually a namespace conflict issue.  If you add
include the iostream header file and add "using namespace std" the code will
not compile, due to a conflict with std::count.

#include <iostream>
using namespace std;

template <class T>
struct templated_struct 
{
        int count;
};

template <class T>
int template_func()
{
        templated_struct<T> s;
        if (s.count < 0) return 0;
        return 0;
}

int main()
{
        template_func<int> ();
        return 0;
}

Now I'm not completely sure if this should be considered a bug.  However, since
count is clearly a member of templated_struct, there shouldn't be a namespace
conflict here.  Also, if you replace '<' with '>' or '==', it compiles fine
with no namespace conflict, which means gcc seems to be confusing '<' with a
template argument.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32408


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

* [Bug c++/32408] Template Parsing Error
  2007-06-19 20:22 [Bug c++/32408] New: Template Parsing Error chsalvia at gmail dot com
                   ` (2 preceding siblings ...)
  2007-06-19 23:08 ` chsalvia at gmail dot com
@ 2007-06-19 23:10 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-19 23:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-06-19 23:10 -------


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


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32408


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

end of thread, other threads:[~2007-06-19 23:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-19 20:22 [Bug c++/32408] New: Template Parsing Error chsalvia at gmail dot com
2007-06-19 21:22 ` [Bug c++/32408] " schwab at suse dot de
2007-06-19 22:04 ` pcarlini at suse dot de
2007-06-19 23:08 ` chsalvia at gmail dot com
2007-06-19 23:10 ` pinskia at gcc dot gnu dot org

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).