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]

Re: [C++ Patch] 28705 & koenig lookup


Mark Mitchell wrote:

But, what if we just issue an error if the only thing we find is a type? Wouldn't that be even more conservative? That program ICEs now, so that's no worse. If finding types becomes OK, then we can add that behavior.

I agree.


I've installed the attached patch to make us give errors on the cases where we currently ICE.

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2006-09-01  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/28705
	* semantics.c (finish_call_expr): Add assert.
	* name-lookup.c (lookup_arg_dependent): Check we found an overload
	or an object.

2006-09-01  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/28705
	* g++.dg/lookup/koenig5.C: New.
	* g++.dg/template/crash56.C: New.

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 116622)
+++ cp/semantics.c	(working copy)
@@ -1754,6 +1754,7 @@ finish_call_expr (tree fn, tree args, bo
 
   /* ARGS should be a list of arguments.  */
   gcc_assert (!args || TREE_CODE (args) == TREE_LIST);
+  gcc_assert (!TYPE_P (fn));
 
   orig_fn = fn;
   orig_args = args;
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 116622)
+++ cp/name-lookup.c	(working copy)
@@ -4668,7 +4668,19 @@ lookup_arg_dependent (tree name, tree fn
   k.namespaces = NULL_TREE;
 
   arg_assoc_args (&k, args);
-  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, k.functions);
+
+  fns = k.functions;
+  
+  if (fns
+      && TREE_CODE (fns) != VAR_DECL
+      && !is_overloaded_fn (fns))
+    {
+      error ("argument dependent lookup finds %q+D", fns);
+      error ("  in call to %qD", name);
+      fns = error_mark_node;
+    }
+    
+  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, fns);
 }
 
 /* Add namespace to using_directives. Return NULL_TREE if nothing was
Index: testsuite/g++.dg/lookup/koenig5.C
===================================================================
--- testsuite/g++.dg/lookup/koenig5.C	(revision 0)
+++ testsuite/g++.dg/lookup/koenig5.C	(revision 0)
@@ -0,0 +1,46 @@
+// Koenig lookup is not defined as intended in the std.  DR 218 gives
+// an indication of what is meant.  This test case encapsulates the
+// current conservative behaviour
+
+// Copyright (C) 2006 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 27 Aug 2006 <nathan@codesourcery.com>
+
+namespace N
+{
+  struct A {};
+  void One (...);  // { dg-error "conflict with" "" }
+  void (*Two) (...);  // { dg-error "not a function" "" }
+  namespace Three {} // { dg-error "lookup finds|not a function" "" }
+}
+
+namespace M
+{
+  struct B {};
+  struct One {};  // { dg-error "lookup finds|not a function" "" }
+  void (*Two) (...);  // { dg-error "conflict with" "" }
+  void Three (...);  // { dg-error "conflict with" "" }
+}
+
+namespace O 
+{
+  struct C {};
+  void Two (...); // { dg-error "conflict with" "" }
+}
+  
+void g (N::A *a, M::B *b, O::C *c)
+{
+  One (a); // ok
+  One (b); // { dg-error "in call to" "" }
+  One (a, b); // { dg-error "in call to" "" }
+
+  Two (a); // ok
+  Two (a, a); // ok
+  Two (b); // ok
+  Two (c); // ok
+  Two (a, b); // { dg-error "in call to" "" }
+  Two (a, c); // { dg-error "in call to" "" }
+  
+  Three (a); // { dg-error "in call to" "" }
+  Three (b); // ok
+  Three (a, b); // { dg-error "in call to" "" }
+}
Index: testsuite/g++.dg/template/crash56.C
===================================================================
--- testsuite/g++.dg/template/crash56.C	(revision 0)
+++ testsuite/g++.dg/template/crash56.C	(revision 0)
@@ -0,0 +1,16 @@
+// Origin: Wolfgang Bangerth <bangerth@dealii.org>
+
+// PR c++/28705
+// DR 218 is debating whether this is well formed or not.  We've never
+// accepted it (because we'd crash), so we continue to reject it, but
+// without crashing.
+
+namespace N
+{
+  struct A { A (A*); }; // { dg-error "lookup finds" "" }
+}
+
+template<typename T> void g (N::A *p)
+{
+  (void) A (p); // { dg-error "in call" "" }
+}

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