OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Oct 2004 16:08:02 +0000 (16:08 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Oct 2004 16:08:02 +0000 (16:08 +0000)
PR c++/17829
* parser.c (cp_parser_postfix_expression): Inhibit Koenig when
unqualified lookup finds a member function.
testsuite:
PR c++/17829
* g++.dg/lookup/koenig4.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88558 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/koenig4.C [new file with mode: 0644]

index dc21cf7..21829a5 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2004-10-04  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        Convert diagnostics to use quoting flag q 4/n
index ed65334..79342db 100644 (file)
@@ -4061,20 +4061,38 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p)
            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.  */
-               if (args
-                   && (is_overloaded_fn (postfix_expression)
-                       || TREE_CODE (postfix_expression) == IDENTIFIER_NODE))
+               else if (args && is_overloaded_fn (postfix_expression))
                  {
-                   koenig_p = true;
-                   postfix_expression
-                     = perform_koenig_lookup (postfix_expression, args);
+                   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);
+                     }
                  }
-               else if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
-                 postfix_expression
-                   = unqualified_fn_lookup_error (postfix_expression);
              }
 
            if (TREE_CODE (postfix_expression) == COMPONENT_REF)
index 2d1277b..8849504 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-05  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/17829
+       * g++.dg/lookup/koenig4.C: New.
+
 2004-10-05  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        * g++.dg/other/classkey1.C: Adjust quoting marks.
@@ -22219,7 +22224,7 @@ Thu Apr 27 15:58:18 MET DST 2000  Jan Hubicka  <jh@suse.cz>
 
        * gcc.c-torture/compile/labels-2.c: New test.
 
-1999-12-27  Martin von Löwis  <loewis@informatik.hu-berlin.de>
+1999-12-27  Martin von Löwis  <loewis@informatik.hu-berlin.de>
 
        * gcc.c-torture/execute/991227-1.c: New test.
 
@@ -22227,7 +22232,7 @@ Thu Apr 27 15:58:18 MET DST 2000  Jan Hubicka  <jh@suse.cz>
 
        * g++.old-deja/g++.pt/instantiate6.C: Remove excess errors XFAIL.
 
-1999-12-21  Martin von Löwis  <loewis@informatik.hu-berlin.de>
+1999-12-21  Martin von Löwis  <loewis@informatik.hu-berlin.de>
 
        * gcc.c-torture/execute/991221-1.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/lookup/koenig4.C b/gcc/testsuite/g++.dg/lookup/koenig4.C
new file mode 100644 (file)
index 0000000..49fa5ea
--- /dev/null
@@ -0,0 +1,21 @@
+// { 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); 
+}