This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Fix 17829
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 05 Oct 2004 17:02:48 +0100
- Subject: [C++ PATCH]: Fix 17829
- Organization: Codesourcery LLC
This patch fixes 17829 where we incorrectly do Koenig lookup.
Why can't we have some kind of uniform container for a set
of overloaded fns, rather than this FUNCTION_DECL/OVERLOAD/TEMPLATE_DECL/
TEMPLATE_ID_EXPR/BASELINK mishmash?
booted & tested on i686-pc-linux-gnu.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-10-05 Nathan Sidwell <nathan@codesourcery.com>
PR c++/17829
* parser.c (cp_parser_postfix_expression): Inhibit Koenig when
unqualified lookup finds a member function.
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.258
diff -c -3 -p -r1.258 parser.c
*** cp/parser.c 4 Oct 2004 06:04:38 -0000 1.258
--- cp/parser.c 5 Oct 2004 15:54:46 -0000
*************** cp_parser_postfix_expression (cp_parser
*** 4063,4082 ****
koenig_p = false;
if (idk == CP_ID_KIND_UNQUALIFIED)
{
/* We do not perform argument-dependent lookup if
normal lookup finds a non-function, in accordance
with the expected resolution of DR 218. */
! if (args
! && (is_overloaded_fn (postfix_expression)
! || TREE_CODE (postfix_expression) == IDENTIFIER_NODE))
{
! koenig_p = true;
! postfix_expression
! = perform_koenig_lookup (postfix_expression, args);
}
- else if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
- postfix_expression
- = unqualified_fn_lookup_error (postfix_expression);
}
if (TREE_CODE (postfix_expression) == COMPONENT_REF)
--- 4063,4100 ----
koenig_p = false;
if (idk == CP_ID_KIND_UNQUALIFIED)
{
+ if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
+ {
+ if (args)
+ {
+ koenig_p = true;
+ postfix_expression
+ = perform_koenig_lookup (postfix_expression, args);
+ }
+ else
+ postfix_expression
+ = unqualified_fn_lookup_error (postfix_expression);
+ }
/* We do not perform argument-dependent lookup if
normal lookup finds a non-function, in accordance
with the expected resolution of DR 218. */
! else if (args && is_overloaded_fn (postfix_expression))
{
! tree fn = get_first_fn (postfix_expression);
!
! if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
! fn = OVL_CURRENT (TREE_OPERAND (fn, 0));
!
! /* Only do argument dependent lookup if regular
! lookup does not find a set of member functions.
! [basic.lookup.koenig]/2a */
! if (!DECL_FUNCTION_MEMBER_P (fn))
! {
! koenig_p = true;
! postfix_expression
! = perform_koenig_lookup (postfix_expression, args);
! }
}
}
if (TREE_CODE (postfix_expression) == COMPONENT_REF)
// { dg-do compile }
// Copyright (C) 2004 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 5 Oct 2004 <nathan@codesourcery.com>
// Origin: Wolfgang Bangerth <bangerth@dealii.org>
// Incorrect koenig lookup
struct A {};
struct B {
static void foo();
static void bar(const A &);
};
void bar(const A &){}
void B::foo () {
A a;
bar (a);
}