This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 2.95.2 -fsyntax-only internal compiler error on struct declaration via nested typedefs


> Alas,   g++ -c    gets exactly the same internal compiler error.

Thanks for your bug report. The problem is that you cannot use a
typedef-name in an elaborated-type-specifier (3.4.4/3); here is a
patch that detects this error.

Jason, Mark, is there no better way to check for a typedef?

Regards,
Martin

2000-01-01  Martin v. Löwis  <loewis@informatik.hu-berlin.de>

	* decl2.c (handle_class_head): Complain about typedefs.

// Build don't link:
struct foo{};
struct bar
{
  typedef int INT;
  typedef foo FOO;
};
int main()
{
  struct bar::INT i; // ERROR - typedef in elaborated type specifier
  struct bar::FOO f; // ERROR - typedef in elaborated type specifier
}

Index: decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.292
diff -u -r1.292 decl2.c
--- decl2.c	1999/12/29 06:39:42	1.292
+++ decl2.c	2000/01/01 18:21:07
@@ -1,5 +1,5 @@
 /* Process declarations and variables for C compiler.
-   Copyright (C) 1988, 92-98, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1988, 92-99, 2000 Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GNU CC.
@@ -5195,7 +5195,16 @@
   tree decl;
 
   if (TREE_CODE (id) == TYPE_DECL)
-    decl = id;
+    {
+      /* 3.4.4/2: If this name lookup finds a typedef­name, the
+         elaborated­type­specifier is ill­formed.  */
+      if (id != TYPE_NAME (TREE_TYPE (id)))
+	{
+	  cp_error ("typedef `%D' in elaborated type specifier", id);
+	  return error_mark_node;
+	}
+      decl = id;
+    }
   else if (DECL_CLASS_TEMPLATE_P (id))
     decl = DECL_TEMPLATE_RESULT (id);
   else 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]