This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
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'
Fix: ?
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
State-Changed-From-To: open->analyzed State-Changed-Why: confirmed as bug
State-Changed-From-To: analyzed->closed State-Changed-Why: oops, like Gaby says -- ill formed
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
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
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.
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
State-Changed-From-To: analyzed->suspended State-Changed-Why: Will be fixed in the new parser.
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...
Responsible-Changed-From-To: unassigned->nathan Responsible-Changed-Why: fixing
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
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.
Reopen all these, because they are duplicates...
*** Bug 14 has been marked as a duplicate of this bug. ***
*** Bug 35 has been marked as a duplicate of this bug. ***
Ah, shouldn't have reopened this PR, since it is the master PR of all the other ones...
*** Bug 1058 has been marked as a duplicate of this bug. ***
*** Bug 1103 has been marked as a duplicate of this bug. ***
*** Bug 3012 has been marked as a duplicate of this bug. ***
*** Bug 3063 has been marked as a duplicate of this bug. ***
*** Bug 4862 has been marked as a duplicate of this bug. ***
*** Bug 5577 has been marked as a duplicate of this bug. ***
*** Bug 8921 has been marked as a duplicate of this bug. ***
*** Bug 9460 has been marked as a duplicate of this bug. ***
*** Bug 9487 has been marked as a duplicate of this bug. ***
*** Bug 9510 has been marked as a duplicate of this bug. ***
*** Bug 9543 has been marked as a duplicate of this bug. ***
*** Bug 9744 has been marked as a duplicate of this bug. ***
*** Bug 10959 has been marked as a duplicate of this bug. ***
*** Bug 11323 has been marked as a duplicate of this bug. ***
*** Bug 11441 has been marked as a duplicate of this bug. ***
*** Bug 11501 has been marked as a duplicate of this bug. ***
*** Bug 11562 has been marked as a duplicate of this bug. ***
*** Bug 4232 has been marked as a duplicate of this bug. ***
*** Bug 11648 has been marked as a duplicate of this bug. ***
*** Bug 13298 has been marked as a duplicate of this bug. ***
*** Bug 13306 has been marked as a duplicate of this bug. ***
*** Bug 13561 has been marked as a duplicate of this bug. ***
*** Bug 13642 has been marked as a duplicate of this bug. ***
*** Bug 14371 has been marked as a duplicate of this bug. ***
*** Bug 14878 has been marked as a duplicate of this bug. ***
*** Bug 11976 has been marked as a duplicate of this bug. ***
*** Bug 8222 has been marked as a duplicate of this bug. ***
*** Bug 16320 has been marked as a duplicate of this bug. ***
*** Bug 17981 has been marked as a duplicate of this bug. ***
*** Bug 18554 has been marked as a duplicate of this bug. ***
*** Bug 19434 has been marked as a duplicate of this bug. ***
*** Bug 23088 has been marked as a duplicate of this bug. ***