This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/27581: ICE using this-pointer in static member function
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 13 May 2006 01:13:58 +0200 (CEST)
- Subject: [patch] Fix PR c++/27581: ICE using this-pointer in static member function
The C++ frontend ICEs on the following invalid code snippet:
struct A
{
template<int> static void foo();
static void bar() { this->A::foo<0>(); }
};
bug.cc: In static member function 'static void A::bar()':
bug.cc:4: error: 'this' is unavailable for static member functions
bug.cc:4: internal compiler error: in adjust_result_of_qualified_name_lookup, at cp/search.c:1488
Please submit a full bug report, [etc.]
Because the this-pointer is invalid, adjust_result_of_qualified_name_lookup
is called with an error_mark_node as context_class. This triggers the
following assert:
gcc_assert (CLASS_TYPE_P (context_class));
The patch fixes this by checking for invalid context_class before.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?
Regards,
Volker
:ADDPATCH C++:
2006-05-12 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27581
* search.c (adjust_result_of_qualified_name_lookup): Skip on
invalid context_class.
===================================================================
--- gcc/gcc/cp/search.c (revision 113720)
+++ gcc/gcc/cp/search.c (working copy)
@@ -1479,7 +1479,8 @@ adjust_result_of_qualified_name_lookup (tree decl,
tree qualifying_scope,
tree context_class)
{
- if (context_class && CLASS_TYPE_P (qualifying_scope)
+ if (context_class && context_class != error_mark_node
+ && CLASS_TYPE_P (qualifying_scope)
&& DERIVED_FROM_P (qualifying_scope, context_class)
&& BASELINK_P (decl))
{
===================================================================
2006-05-12 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27581
* g++.dg/lookup/this1.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/lookup/this1.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/lookup/this1.C 2006-05-12 17:22:07 +0200
@@ -0,0 +1,8 @@
+// PR c++/27581
+// { dg-do compile }
+
+struct A
+{
+ template<int> static void foo();
+ static void bar() { this->A::foo<0>(); } // { dg-error "unavailable" }
+};
===================================================================