This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH for 3.3] Fix implicit typename warning regression (revised)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 7 Jun 2003 23:27:26 +0700 (ICT)
- Subject: [C++ PATCH for 3.3] Fix implicit typename warning regression (revised)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This revised version fixes the implicit typename warning in friend
declarations by dealing with it much earlier. With the patch,
the problem is caught while parsing the elaborated type specifier.
Here implicit typename is turned into an ordinary typename.
However, some error checking inside begin_class_definition still
requires implicit typename to be retained in order to distinguish
between these two cases:
template <class T> class A::B { ... } // Legal
template <class T> typename A::B { ... } // Illegal
so the implicit typename is converted when we are not parsing
a class definition.
Tested on i686-pc-linux-gnu. OK for 3.3 branch?
--Kriang
2003-06-07 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/11039
* decl2.c (handle_class_head): Remove implicitness in typename
appeared as elaborated type specifier in declaration.
2003-06-07 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/11039
* g++.dg/warn/implicit-typename2.C: New test.
* g++.dg/warn/implicit-typename3.C: New test.
diff -cprN gcc-33-save/gcc/cp/decl2.c gcc-33-new/gcc/cp/decl2.c
*** gcc-33-save/gcc/cp/decl2.c Tue May 6 19:10:20 2003
--- gcc-33-new/gcc/cp/decl2.c Sat Jun 7 21:04:27 2003
*************** handle_class_head (tag_kind, scope, id,
*** 5006,5011 ****
--- 5006,5027 ----
if (!xrefd_p && PROCESSING_REAL_TEMPLATE_DECL_P ())
decl = push_template_decl (decl);
}
+ else
+ {
+ /* For elaborated type specifier in declaration like
+
+ class A::B *a;
+
+ we get an implicit typename here. Let's remove its
+ implicitness so that we don't issue any implicit
+ typename warning later. Note that when defn_p is true,
+ implicitness is still required by begin_class_definition. */
+ if (IMPLICIT_TYPENAME_P (type))
+ decl = TYPE_STUB_DECL (build_typename_type (TYPE_CONTEXT (type),
+ TYPE_IDENTIFIER (type),
+ TYPENAME_TYPE_FULLNAME (type),
+ NULL_TREE));
+ }
return decl;
}
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/warn/implicit-typename2.C gcc-33-new/gcc/testsuite/g++.dg/warn/implicit-typename2.C
*** gcc-33-save/gcc/testsuite/g++.dg/warn/implicit-typename2.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/warn/implicit-typename2.C Fri Jun 6 21:02:50 2003
***************
*** 0 ****
--- 1,12 ----
+ // { dg-do compile }
+
+ // Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+ // PR c++/11039: Implicit typename warning in friend class declaration.
+
+ template <typename T> struct X {
+ struct Y {
+ struct Z {};
+ };
+ friend struct Y::Z;
+ };
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/warn/implicit-typename3.C gcc-33-new/gcc/testsuite/g++.dg/warn/implicit-typename3.C
*** gcc-33-save/gcc/testsuite/g++.dg/warn/implicit-typename3.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/warn/implicit-typename3.C Sat Jun 7 20:21:27 2003
***************
*** 0 ****
--- 1,12 ----
+ // { dg-do compile }
+
+ // Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+ // PR c++/11039: Implicit typename warning in friend class declaration.
+
+ template <typename T> struct X {
+ struct Y {
+ struct Z {};
+ };
+ template <typename U> friend struct Y::Z f(U);
+ };