* g++ 3.4 more restrictive than g++ 3.3 ? @ 2005-07-15 12:47 Mathieu Fluhr 2005-07-15 13:09 ` Oliver Kullmann 0 siblings, 1 reply; 3+ messages in thread From: Mathieu Fluhr @ 2005-07-15 12:47 UTC (permalink / raw) To: gcc-help Hello all I'm just wondering about some differences between g++ 3.3 (3.3.6) and g++ 3.4 (3.4.5). Please have a look to this piece of code: ---8<--------------------------------------------- #include <iostream> template <class ValueType> class A { protected: ValueType m_Field; }; template <class ValueType> class B : public A<ValueType> { void TestParam(ValueType i) { m_Field = i; } }; int main(void) { return 0; } ---8<--------------------------------------------- As far as I know the C++ language, syntax seems to be correct, and g++ 3.3 does not output any error/warning (even with -Wall option). The problem is that g++ 3.4 (and 4.0 btw) outputs the following: For g++ 3.4: Inherit.cpp: In member function `void B<ValueType>::TestParam(ValueType)': Inherit.cpp:16: error: `m_Field' undeclared (first use this function) Inherit.cpp:16: error: (Each undeclared identifier is reported only once for each function it appears in.) For g++ 4.0: Inherit.cpp: In member function 'void B<ValueType>::TestParam(ValueType)': Inherit.cpp:16: error: 'm_Field' was not declared in this scope The very weird thing is that if I change the line 16 from m_Field = i; to this->m_Field = i; everything works without any kind of problem !!! So is this behaviour normal ? Best Regards, Mathieu Fluhr ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: g++ 3.4 more restrictive than g++ 3.3 ? 2005-07-15 12:47 g++ 3.4 more restrictive than g++ 3.3 ? Mathieu Fluhr @ 2005-07-15 13:09 ` Oliver Kullmann [not found] ` <1121436079.21076.12.camel@localhost.localdomain> 0 siblings, 1 reply; 3+ messages in thread From: Oliver Kullmann @ 2005-07-15 13:09 UTC (permalink / raw) To: Mathieu Fluhr; +Cc: gcc-help On Fri, Jul 15, 2005 at 02:46:50PM +0200, Mathieu Fluhr wrote: > Hello all > > I'm just wondering about some differences between g++ 3.3 (3.3.6) and > g++ 3.4 (3.4.5). Please have a look to this piece of code: > > ---8<--------------------------------------------- > #include <iostream> > > template <class ValueType> > class A > { > protected: > ValueType m_Field; > }; > > template <class ValueType> > class B : public A<ValueType> > { > void TestParam(ValueType i) > { > m_Field = i; > } > }; > > int main(void) > { > return 0; > } > > ---8<--------------------------------------------- > > As far as I know the C++ language, syntax seems to be correct, and g++ > 3.3 does not output any error/warning (even with -Wall option). The > problem is that g++ 3.4 (and 4.0 btw) outputs the following: > > For g++ 3.4: > > Inherit.cpp: In member function `void > B<ValueType>::TestParam(ValueType)': > Inherit.cpp:16: error: `m_Field' undeclared (first use this function) > Inherit.cpp:16: error: (Each undeclared identifier is reported only once > for each function it appears in.) > > For g++ 4.0: > > Inherit.cpp: In member function 'void > B<ValueType>::TestParam(ValueType)': > Inherit.cpp:16: error: 'm_Field' was not declared in this scope > > > The very weird thing is that if I change the line 16 from > m_Field = i; > to > this->m_Field = i; > > everything works without any kind of problem !!! So is this behaviour > normal ? > Hi, that's exactly correct: class B has a dependent base class, and thus members of this base class have to be qualified (see the standard, paragraph 14.6.2, point 4). Oliver P.S. A minor point: I think "int main(void)" is not standard --- according to 3.6.1, point 2 only "int main()" is guaranteed to work. ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <1121436079.21076.12.camel@localhost.localdomain>]
* Re: g++ 3.4 more restrictive than g++ 3.3 ? [not found] ` <1121436079.21076.12.camel@localhost.localdomain> @ 2005-07-15 14:36 ` Oliver Kullmann 0 siblings, 0 replies; 3+ messages in thread From: Oliver Kullmann @ 2005-07-15 14:36 UTC (permalink / raw) To: Mathieu Fluhr; +Cc: gcc-help On Fri, Jul 15, 2005 at 04:01:19PM +0200, Mathieu Fluhr wrote: > Thanks for you quick answer. So I assume the best solution is to patch > all C++ files that brings errors... Lots of work in perspective ;-) > but necessary > BtW, regarding your PS, what is the difference between > `int main(void)` and `int main()` ? > it's just that I'm not aware of text in the standard granting the use of `int main(void)`, while `int main()` definitely is correct, so it might be that at some time in the future `int main(void)` has to be changed to `int main()`, and so I would avoid it. Oliver > Mathieu > > On ven, 2005-07-15 at 14:09 +0100, Oliver Kullmann wrote: > > On Fri, Jul 15, 2005 at 02:46:50PM +0200, Mathieu Fluhr wrote: > > > Hello all > > > > > > I'm just wondering about some differences between g++ 3.3 (3.3.6) and > > > g++ 3.4 (3.4.5). Please have a look to this piece of code: > > > > > > ---8<--------------------------------------------- > > > #include <iostream> > > > > > > template <class ValueType> > > > class A > > > { > > > protected: > > > ValueType m_Field; > > > }; > > > > > > template <class ValueType> > > > class B : public A<ValueType> > > > { > > > void TestParam(ValueType i) > > > { > > > m_Field = i; > > > } > > > }; > > > > > > int main(void) > > > { > > > return 0; > > > } > > > > > > ---8<--------------------------------------------- > > > > > > As far as I know the C++ language, syntax seems to be correct, and g++ > > > 3.3 does not output any error/warning (even with -Wall option). The > > > problem is that g++ 3.4 (and 4.0 btw) outputs the following: > > > > > > For g++ 3.4: > > > > > > Inherit.cpp: In member function `void > > > B<ValueType>::TestParam(ValueType)': > > > Inherit.cpp:16: error: `m_Field' undeclared (first use this function) > > > Inherit.cpp:16: error: (Each undeclared identifier is reported only once > > > for each function it appears in.) > > > > > > For g++ 4.0: > > > > > > Inherit.cpp: In member function 'void > > > B<ValueType>::TestParam(ValueType)': > > > Inherit.cpp:16: error: 'm_Field' was not declared in this scope > > > > > > > > > The very weird thing is that if I change the line 16 from > > > m_Field = i; > > > to > > > this->m_Field = i; > > > > > > everything works without any kind of problem !!! So is this behaviour > > > normal ? > > > > > > > Hi, > > > > that's exactly correct: class B has a dependent base class, and > > thus members of this base class have to be qualified (see the standard, > > paragraph 14.6.2, point 4). > > > > Oliver > > > > P.S. A minor point: I think "int main(void)" is not standard > > --- according to 3.6.1, point 2 only "int main()" is guaranteed > > to work. > > > -- Dr. Oliver Kullmann Computer Science Department University of Wales Swansea Faraday Building, Singleton Park Swansea SA2 8PP, UK http://cs-svr1.swan.ac.uk/~csoliver/ ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-07-15 14:36 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-07-15 12:47 g++ 3.4 more restrictive than g++ 3.3 ? Mathieu Fluhr 2005-07-15 13:09 ` Oliver Kullmann [not found] ` <1121436079.21076.12.camel@localhost.localdomain> 2005-07-15 14:36 ` Oliver Kullmann
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).