This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

[patch] Fix PR c++/27933: ICE with invalid "using"


The following code snippet triggers an ICE in the C++ frontend:

  template<int> struct A
  {
    int i;
    A() { using i; }
  };

  A<0> b;

bug.cc: In constructor 'A<<anonymous> >::A()':
bug.cc:4: error: expected nested-name-specifier before 'i'
bug.cc:4: error: 'i' not declared
bug.cc: In constructor 'A<<anonymous> >::A() [with int <anonymous> = 0]':
bug.cc:7:   instantiated from here
bug.cc:4: internal compiler error: Segmentation fault
Please submit a full bug report, [etc.]

We segfault in tsubst in pt.c after the call to lookup_qualified_name:

  decl = lookup_qualified_name (scope, name,
				/*is_type_p=*/false,
				/*complain=*/false);
  if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)

For the testcase above we have decl == NULL_TREE. So we crash trying to
determine TREE_CODE (decl). According to the comment above
lookup_qualified_name, the function should return error_mark_node
(and not NULL_TREE) if no suitable candidate is found. The patch fixes
the ICE by doing so and reorganizes the code a little.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?

Regards,
Volker

:ADDPATCH C++:


2006-06-07  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27933
	* name-lookup.c (lookup_qualified_name): Always return error_mark_node
	if lookup fails.

===================================================================
--- gcc/gcc/cp/name-lookup.c	(revision 114427)
+++ gcc/gcc/cp/name-lookup.c	(working copy)
@@ -3713,6 +3713,7 @@ lookup_qualified_name (tree scope, tree name,
 lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain)
 {
   int flags = 0;
+  tree t = NULL_TREE;
 
   if (TREE_CODE (scope) == NAMESPACE_DECL)
     {
@@ -3722,16 +3723,13 @@
       if (is_type_p)
 	flags |= LOOKUP_PREFER_TYPES;
       if (qualified_lookup_using_namespace (name, scope, &binding, flags))
-	return select_decl (&binding, flags);
+	t = select_decl (&binding, flags);
     }
   else if (is_aggr_type (scope, complain))
-    {
-      tree t;
-      t = lookup_member (scope, name, 2, is_type_p);
-      if (t)
-	return t;
-    }
+    t = lookup_member (scope, name, 2, is_type_p);
 
+  if (t)
+    return t;
   return error_mark_node;
 }
 
===================================================================

2006-06-07  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27933
	* g++.dg/lookup/using15.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/lookup/using15.C	2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/lookup/using15.C	2006-06-07 10:34:12 +0200
@@ -0,0 +1,10 @@
+// PR c++/27933
+// { dg-do compile }
+
+template<int> struct A
+{
+  int i;
+  A() { using i; }  // { dg-error "nested-name-specifier|declared" }
+};
+
+A<0> b;
===================================================================



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