This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [wwwdocs] Additional C++ entries in changes.html
Gabriel Dos Reis wrote:
>> + <li>In templates, all non-dependent names are now looked up
>> and bound + at definition time (while parsing the code), instead of
>> later when + the template is instantiated. This is known as
>> "two-stage name + look-up".
>
> I still maintain my objection to the last sentence. If you don't want
> to be precise about "two-phase name lookup", simply remove that
> sentence. There is no emergency to add to the existing confusion.
Sorry, I missed this objection while reviewing the disussion. To make things
easier, I just removed the sentence, and this is the updated diff. OK to
commit?
Giovanni Bajo
Index: changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-3.4/changes.html,v
retrieving revision 1.95
diff -c -3 -p -r1.95 changes.html
*** changes.html 3 Feb 2004 06:39:33 -0000 1.95
--- changes.html 8 Feb 2004 20:43:46 -0000
***************
*** 259,264 ****
--- 259,271 ----
<h3>C++</h3>
<ul>
+ <li>G++ is now <strong>much</strong> closer to full conformance to
+ the ISO/ANSI C++ standard. This means, among other things, that a lot
+ of invalid constructs which used to be accepted in previous versions
+ will now be rejected. It is very likely that existing C++ code will
+ need to be fixed to be more conformant, in order to compile. This
+ document lists some of the most common issues.</li>
+
<li>A hand-written recursive-descent C++ parser has replaced the
YACC-derived C++ parser from previous GCC releases. The new
parser contains much improved infrastructure needed for better
***************
*** 269,280 ****
<li>You must now use the <code>typename</code> and
<code>template</code> keywords to disambiguate dependent names,
! as required by the C++ standard.</li>
<li>In a template definition, unqualified names will no longer
find members of a dependent base. For example,
<pre>
! template <typename T>struct B {
int m;
int n;
int f ();
--- 276,334 ----
<li>You must now use the <code>typename</code> and
<code>template</code> keywords to disambiguate dependent names,
! as required by the C++ standard.
!
! <pre>
! struct K {
! typedef int mytype_t;
! };
!
! template <class T1> struct A {
! template <class T2> struct B {
! void callme(void);
! };
!
! template <int N> void bar(void)
! {
! // Use 'typename' to tell the parser that T1::mytype_t names
! // a type. This is needed because the name is dependent (in
! // this case, on template parameter T1).
! typename T1::mytype_t x;
! x = 0;
! }
! };
!
! template <class T> void template_func(void)
! {
! // Use 'template' to prefix member templates within
! // dependent types (a has type A<T>, which depends on
! // the template parameter T).
! A<T> a;
! a.template bar<0>();
!
! // Use 'template' to tell the parser that B is a nested
! // template class (dependent on template parameter T), and
! // 'typename' because the whole A<T>::B<int> is
! // the name of a type (again, dependent).
! typename A<T>::template B<int> b;
! b.callme();
! }
!
! void non_template_func(void)
! {
! // Outside of any template class or function, no names can be
! // dependent, so the use of the keyword 'typename' and 'template'
! // is not needed (and actually forbidden).
! A<K> a;
! a.bar<0>();
! A<K>::B<float> b;
! b.callme();
! }</pre></li>
<li>In a template definition, unqualified names will no longer
find members of a dependent base. For example,
<pre>
! template <typename T> struct B {
int m;
int n;
int f ();
***************
*** 303,308 ****
--- 357,393 ----
this->g ();
}</pre></li>
+ <li>In templates, all non-dependent names are now looked up and bound
+ at definition time (while parsing the code), instead of later when
+ the template is instantiated. For instance:
+
+ <pre>
+ void foo(int);
+
+ template <int> struct A {
+ static void bar(void){
+ foo('a');
+ }
+ };
+
+ void foo(char);
+
+ int main()
+ {
+ A<0>::bar(); // Calls foo(int), used to call foo(char).
+ }
+ </pre></li>
+
+ <li>In an explicit instantiation of a class template, you must use
+ <code>class</code> or <code>struct</code> before the template-id:
+
+ <pre>
+ template <int N>
+ class A {};
+
+ template A<0>; // error, not accepted anymore
+ template class A<0>; // OK</pre></li>
+
<li>The "named return value" and "implicit typename"
extensions have been removed.</li>
***************
*** 420,425 ****
--- 505,526 ----
<code>NULL</code>. These changes are incorporated into the
libstdc++ runtime library.</li>
+ <li>Using a name introduced by a typedef in a friend declaration or in an
+ explicit instantiation is now rejected, as specified by the ISO C++
+ standard.
+ <pre>
+ class A;
+ typedef A B;
+ class C {
+ friend class B; // error, no typedef name here
+ friend B; // error, friend always needs class/struct/enum
+ friend class A; // OK
+ };
+
+ template <int> class Q {};
+ typedef Q<0> R;
+ template class R; // error, no typedef name here
+ template class Q<0>; // OK</pre></li>
</ul>
<h3>Objective-C</h3>