First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 795
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Nathan Sidwell <nathan@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: sadowski@lucent.com
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
b.tar.gz b.tar.gz application/x-gzip 2003-05-21 15:16 38.71 KB Edit
795.1 795.1 application/octet-stream 2003-05-21 15:16 1.50 KB Edit
795-2 795-2 application/octet-stream 2003-05-21 15:16 1.87 KB Edit
795-3 795-3 application/octet-stream 2003-05-21 15:16 1.21 KB Edit
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 795 depends on: Show dependency tree
Show dependency graph
Bug 795 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2003-01-01 00:00 Opened: 2000-11-14 01:46
Considering the following code:
/////
# include <iostream>
# include <vector>

using namespace std ;

class V
{
public:
  template<typename T>
  T get() const {
    return ( 1.2345 ) ;
  }
} ;

class L
{
public:
  L( V const & v ) : _v() { _v.push_back( v ) ; }

  template<typename T>
  T at( int i ) const {
    return _v[i].get<T>() ; ///// <- (a) Parse error here
  }

private:
  std::vector<V> _v ;
} ;

int main()
{
  V d ;  
  cerr << d.get<double>() << endl ; ///// <- (b) This works

  L l( d ) ;
  cerr << l.at<double>( 0 ) << endl ;

  return 0 ; 
}
/////

I get a parse error before `>'.
Nevertheless, if the offending line (a) is replaced by 
something like `return 2.3451 ;', the compilation is 
successful although line (b) seems to use the same 
kind of syntax (except that the template parameter is 
replaced by an actual type).

Is this a bug, or am I trying something forbidden by 
the language?

Thanks for your help (and your compiler)

------
Here's a simpler example:
  struct X {
    template <class T> T* f()  { return (T*) 0; }
  };

  template <class T>
  int* g(T) {
    X x;
    return x.f<int>();
  }
The compiler is applying the rule in 14.2p4 in appropriately: it's acting as if x is a dependent name.

Release:
2.95.2 20000220

Environment:
i386-linux
(Debian GNU/Linux)

How-To-Repeat:
Try to compile `b.cc'

------- Comment #1 From sadowski@lucent.com 2000-11-14 01:46 -------
Fix:
?

------- Comment #2 From Gabriel Dos Reis 2000-11-14 15:26 -------
From: Gabriel Dos Reis <gdr@codesourcery.com>
To: sadowski@lucent.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/795: parse error in member template method
Date: 14 Nov 2000 15:26:06 +0100

 sadowski@lucent.com writes:
 
 [...]
 
 |   template<typename T>
 |   T at( int i ) const {
 |     return _v[i].get<T>() ; ///// <- (a) Parse error here
                   ^^ 
 You need to put int the `template' keyword as follows:
 
 	return _v[i].template get<T>();
 
 -- Gaby
 CodeSourcery, LLC                       http://www.codesourcery.com

------- Comment #3 From Nathan Sidwell 2000-11-24 01:42 -------
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed as bug

------- Comment #4 From Nathan Sidwell 2000-11-24 06:08 -------
State-Changed-From-To: analyzed->closed
State-Changed-Why: oops, like Gaby says -- ill formed

------- Comment #5 From Nathan Sidwell 2000-11-24 09:43 -------
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, sadowski@lucent.com
Cc:  
Subject: Re: c++/795
Date: 24 Nov 2000 09:43:00 -0000

 Synopsis: parse error in member template method
 
 State-Changed-From-To: open->analyzed
 State-Changed-By: nathan
 State-Changed-When: Fri Nov 24 01:42:59 2000
 State-Changed-Why:
     confirmed as bug
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=795&database=gcc

------- Comment #6 From Nathan Sidwell 2000-11-24 14:08 -------
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, sadowski@lucent.com
Cc:  
Subject: Re: c++/795
Date: 24 Nov 2000 14:08:23 -0000

 Synopsis: parse error in member template method
 
 State-Changed-From-To: analyzed->closed
 State-Changed-By: nathan
 State-Changed-When: Fri Nov 24 06:08:23 2000
 State-Changed-Why:
     oops, like Gaby says -- ill formed
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=795&database=gcc

------- Comment #7 From Nathan Sidwell 2000-11-28 01:42 -------
State-Changed-From-To: closed->analyzed
State-Changed-Why: There's a defect report http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#30
    about this. Basically if the thing on the left of the ., -> or
    :: does not depend on template parameters, there should
    be no `template' keyword following.
    I've attached mail about this (containing some examples)
    from Martin Sebor.

------- Comment #8 From Nathan Sidwell 2000-11-28 09:42 -------
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, sadowski@lucent.com
Cc:  
Subject: Re: c++/795
Date: 28 Nov 2000 09:42:11 -0000

 Synopsis: parse error in member template method
 
 State-Changed-From-To: closed->analyzed
 State-Changed-By: nathan
 State-Changed-When: Tue Nov 28 01:42:11 2000
 State-Changed-Why:
     There's a defect report http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#30
     about this. Basically if the thing on the left of the ., -> or
     :: does not depend on template parameters, there should
     be no `template' keyword following.
     I've attached mail about this (containing some examples)
     from Martin Sebor.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=795&database=gcc

------- Comment #9 From Kriang Lerdsuwanakij 2002-07-28 04:28 -------
State-Changed-From-To: analyzed->suspended
State-Changed-Why: Will be fixed in the new parser.

------- Comment #10 From Gabriel Dos Reis 2002-12-29 12:57 -------
State-Changed-From-To: suspended->analyzed
State-Changed-Why: Still not fixed in the new parser.  Not we get:
    795.C: In member function `T L::at(int) const':
    795.C:22: error: expected primary-expression
    795.C:22: error: expected primary-expression
    
    Note how the diagnostic is duplicated...

------- Comment #11 From Nathan Sidwell 2003-01-23 16:49 -------
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: fixing

------- Comment #12 From Nathan Sidwell 2003-01-25 18:02 -------
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/795
Date: 25 Jan 2003 18:02:43 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	nathan@gcc.gnu.org	2003-01-25 18:02:43
 
 Modified files:
 	gcc/cp         : ChangeLog parser.c pt.c semantics.c 
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/g++.old-deja/g++.brendan: parse3.C 
 	gcc/testsuite/g++.old-deja/g++.ns: bogus1.C 
 	gcc/testsuite/g++.old-deja/g++.pt: memclass5.C 
 Added files:
 	gcc/testsuite/g++.dg/parse: template3.C template4.C 
 	gcc/testsuite/g++.dg/template: qual2.C 
 
 Log message:
 	cp:
 	PR c++/9403
 	* parser.c (cp_parser_class_or_namespace_name): Reject duplicate
 	template keyword.
 	(cp_parser_base_specifier): Look for and consume a
 	TEMPLATE keyword. Replace switch with array index.
 	
 	PR c++/795
 	* semantics.c (finish_non_static_data_member): Remember the
 	field's type even in a template.
 	
 	PR c++/9415
 	* pt.c (tsubst_copy_and_build, CALL_EXPR): BASELINK exprs are
 	already scoped.
 	
 	PR c++/8545
 	* parser.c (cp_parser_cast_expression): Be more tentative.
 	testsuite:
 	PR c++/9403
 	* g++.dg/parse/template3.C: New test.
 	* g++.old-deja/g++.pt/memclass5.C: Add needed template keyword.
 	
 	PR c++/795
 	* g++.dg/parse/template4.C: New test.
 	
 	PR c++/9415
 	* g++.dg/template/qual2.C: New test.
 	
 	PR c++/8545
 	* g++.old-deja/g++.brendan/parse3.C: Remove XFAIL.
 	
 	* g++.old-deja/g++.ns/bogus1.C: Change expected error.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3178&r2=1.3179
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.38&r2=1.39
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.652&r2=1.653
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.295&r2=1.296
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2368&r2=1.2369
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/template3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/template4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/qual2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.brendan/parse3.C.diff?cvsroot=gcc&r1=1.5&r2=1.6
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.ns/bogus1.C.diff?cvsroot=gcc&r1=1.2&r2=1.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/memclass5.C.diff?cvsroot=gcc&r1=1.5&r2=1.6
 


------- Comment #13 From Nathan Sidwell 2003-01-25 18:02 -------
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/795
Date: 25 Jan 2003 18:02:43 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	nathan@gcc.gnu.org	2003-01-25 18:02:43
 
 Modified files:
 	gcc/cp         : ChangeLog parser.c pt.c semantics.c 
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/g++.old-deja/g++.brendan: parse3.C 
 	gcc/testsuite/g++.old-deja/g++.ns: bogus1.C 
 	gcc/testsuite/g++.old-deja/g++.pt: memclass5.C 
 Added files:
 	gcc/testsuite/g++.dg/parse: template3.C template4.C 
 	gcc/testsuite/g++.dg/template: qual2.C 
 
 Log message:
 	cp:
 	PR c++/9403
 	* parser.c (cp_parser_class_or_namespace_name): Reject duplicate
 	template keyword.
 	(cp_parser_base_specifier): Look for and consume a
 	TEMPLATE keyword. Replace switch with array index.
 	
 	PR c++/795
 	* semantics.c (finish_non_static_data_member): Remember the
 	field's type even in a template.
 	
 	PR c++/9415
 	* pt.c (tsubst_copy_and_build, CALL_EXPR): BASELINK exprs are
 	already scoped.
 	
 	PR c++/8545
 	* parser.c (cp_parser_cast_expression): Be more tentative.
 	testsuite:
 	PR c++/9403
 	* g++.dg/parse/template3.C: New test.
 	* g++.old-deja/g++.pt/memclass5.C: Add needed template keyword.
 	
 	PR c++/795
 	* g++.dg/parse/template4.C: New test.
 	
 	PR c++/9415
 	* g++.dg/template/qual2.C: New test.
 	
 	PR c++/8545
 	* g++.old-deja/g++.brendan/parse3.C: Remove XFAIL.
 	
 	* g++.old-deja/g++.ns/bogus1.C: Change expected error.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3178&r2=1.3179
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.38&r2=1.39
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.652&r2=1.653
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.295&r2=1.296
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2368&r2=1.2369
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/template3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/template4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/qual2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.brendan/parse3.C.diff?cvsroot=gcc&r1=1.5&r2=1.6
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.ns/bogus1.C.diff?cvsroot=gcc&r1=1.2&r2=1.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/memclass5.C.diff?cvsroot=gcc&r1=1.5&r2=1.6
 

------- Comment #14 From Nathan Sidwell 2003-01-27 21:56 -------
State-Changed-From-To: analyzed->closed
State-Changed-Why: PR c++/795
    	* semantics.c (finish_non_static_data_member): Remember the
    	field's type even in a template.

------- Comment #15 From Wolfgang Bangerth 2003-07-17 23:16 -------
Reopen all these, because they are duplicates...

------- Comment #16 From Wolfgang Bangerth 2003-07-17 23:17 -------
*** Bug 14 has been marked as a duplicate of this bug. ***

------- Comment #17 From Wolfgang Bangerth 2003-07-17 23:18 -------
*** Bug 35 has been marked as a duplicate of this bug. ***

------- Comment #18 From Wolfgang Bangerth 2003-07-17 23:19 -------
Ah, shouldn't have reopened this PR, since it is the master PR of all the
other ones...

------- Comment #19 From Wolfgang Bangerth 2003-07-17 23:19 -------
*** Bug 1058 has been marked as a duplicate of this bug. ***

------- Comment #20 From Wolfgang Bangerth 2003-07-17 23:19 -------
*** Bug 1103 has been marked as a duplicate of this bug. ***

------- Comment #21 From Wolfgang Bangerth 2003-07-17 23:20 -------
*** Bug 3012 has been marked as a duplicate of this bug. ***

------- Comment #22 From Wolfgang Bangerth 2003-07-17 23:20 -------
*** Bug 3063 has been marked as a duplicate of this bug. ***

------- Comment #23 From Wolfgang Bangerth 2003-07-17 23:21 -------
*** Bug 4862 has been marked as a duplicate of this bug. ***

------- Comment #24 From Wolfgang Bangerth 2003-07-17 23:21 -------
*** Bug 5577 has been marked as a duplicate of this bug. ***

------- Comment #25 From Wolfgang Bangerth 2003-07-17 23:21 -------
*** Bug 8921 has been marked as a duplicate of this bug. ***

------- Comment #26 From Wolfgang Bangerth 2003-07-17 23:22 -------
*** Bug 9460 has been marked as a duplicate of this bug. ***

------- Comment #27 From Wolfgang Bangerth 2003-07-17 23:22 -------
*** Bug 9487 has been marked as a duplicate of this bug. ***

------- Comment #28 From Wolfgang Bangerth 2003-07-17 23:22 -------
*** Bug 9510 has been marked as a duplicate of this bug. ***

------- Comment #29 From Wolfgang Bangerth 2003-07-17 23:23 -------
*** Bug 9543 has been marked as a duplicate of this bug. ***

------- Comment #30 From Wolfgang Bangerth 2003-07-17 23:23 -------
*** Bug 9744 has been marked as a duplicate of this bug. ***

------- Comment #31 From Wolfgang Bangerth 2003-07-17 23:24 -------
*** Bug 10959 has been marked as a duplicate of this bug. ***

------- Comment #32 From Wolfgang Bangerth 2003-07-17 23:24 -------
*** Bug 11323 has been marked as a duplicate of this bug. ***

------- Comment #33 From Wolfgang Bangerth 2003-07-17 23:24 -------
*** Bug 11441 has been marked as a duplicate of this bug. ***

------- Comment #34 From Wolfgang Bangerth 2003-07-17 23:25 -------
*** Bug 11501 has been marked as a duplicate of this bug. ***

------- Comment #35 From Wolfgang Bangerth 2003-07-17 23:25 -------
*** Bug 11562 has been marked as a duplicate of this bug. ***

------- Comment #36 From Andrew Pinski 2003-07-17 23:30 -------
*** Bug 4232 has been marked as a duplicate of this bug. ***

------- Comment #37 From Andrew Pinski 2003-07-23 20:50 -------
*** Bug 11648 has been marked as a duplicate of this bug. ***

------- Comment #38 From Andrew Pinski 2003-12-04 09:18 -------
*** Bug 13298 has been marked as a duplicate of this bug. ***

------- Comment #39 From Andrew Pinski 2003-12-04 22:56 -------
*** Bug 13306 has been marked as a duplicate of this bug. ***

------- Comment #40 From Andrew Pinski 2004-01-04 08:15 -------
*** Bug 13561 has been marked as a duplicate of this bug. ***

------- Comment #41 From Andrew Pinski 2004-01-11 07:41 -------
*** Bug 13642 has been marked as a duplicate of this bug. ***

------- Comment #42 From Andrew Pinski 2004-03-01 20:32 -------
*** Bug 14371 has been marked as a duplicate of this bug. ***

------- Comment #43 From Andrew Pinski 2004-04-07 15:02 -------
*** Bug 14878 has been marked as a duplicate of this bug. ***

------- Comment #44 From Andrew Pinski 2004-04-21 02:16 -------
*** Bug 11976 has been marked as a duplicate of this bug. ***

------- Comment #45 From Andrew Pinski 2004-04-21 02:58 -------
*** Bug 8222 has been marked as a duplicate of this bug. ***

------- Comment #46 From Andrew Pinski 2004-07-01 19:40 -------
*** Bug 16320 has been marked as a duplicate of this bug. ***

------- Comment #47 From Andrew Pinski 2004-10-13 20:18 -------
*** Bug 17981 has been marked as a duplicate of this bug. ***

------- Comment #48 From Andrew Pinski 2004-11-18 20:33 -------
*** Bug 18554 has been marked as a duplicate of this bug. ***

------- Comment #49 From Andrew Pinski 2005-01-14 00:41 -------
*** Bug 19434 has been marked as a duplicate of this bug. ***

------- Comment #50 From Andrew Pinski 2005-07-26 21:30 -------
*** Bug 23088 has been marked as a duplicate of this bug. ***

First Last Prev Next    No search results available      Search page      Enter new bug