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]

[C++ PATCH]: Fix 11617


Hi,
this fixes 11617 where we failed to diagnose a missing qualified-id.

booted & tested on i686-pc-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
         The voices in my head said this was stupid too
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2003-07-25  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/11617
	* cp-tree.h (nested_name_lookup_error): Declare.
	* pt.c (tsubst_qualified_id): Use nested_name_lookup_error for
	errors.
	(tsubst_expr) <DECL_STMT case>: Likewise.
	(tsubst_copy_and_build) <COMPONENT_REF case>: Likewise.
	* semantics.c (nested_name_lookup_error): New, broken out of ...
	(finish_id_expression): ... here. Use it.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.887
diff -c -3 -p -r1.887 cp-tree.h
*** cp/cp-tree.h	24 Jul 2003 23:33:25 -0000	1.887
--- cp/cp-tree.h	25 Jul 2003 09:58:33 -0000
*************** extern tree finish_template_type        
*** 4159,4164 ****
--- 4159,4165 ----
  extern tree finish_base_specifier               (tree, tree, bool);
  extern void finish_member_declaration           (tree);
  extern void check_multiple_declarators          (void);
+ extern void nested_name_lookup_error		(tree, tree);
  extern tree finish_id_expression                (tree, tree, tree,
  						 cp_id_kind *, tree *,
  						 bool, bool, bool *, 
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.734
diff -c -3 -p -r1.734 pt.c
*** cp/pt.c	22 Jul 2003 23:30:19 -0000	1.734
--- cp/pt.c	25 Jul 2003 10:00:06 -0000
*************** tsubst_qualified_id (tree qualified_id, 
*** 7157,7164 ****
      }
  
    if (!BASELINK_P (name) && !DECL_P (expr))
!     expr = lookup_qualified_name (scope, expr, /*is_type_p=*/0,
! 				  (complain & tf_error) != 0);
    if (DECL_P (expr))
      check_accessibility_of_qualified_id (expr, 
  					 /*object_type=*/NULL_TREE,
--- 7157,7163 ----
      }
  
    if (!BASELINK_P (name) && !DECL_P (expr))
!     expr = lookup_qualified_name (scope, expr, /*is_type_p=*/0, false);
    if (DECL_P (expr))
      check_accessibility_of_qualified_id (expr, 
  					 /*object_type=*/NULL_TREE,
*************** tsubst_qualified_id (tree qualified_id, 
*** 7175,7181 ****
    if (is_template)
      expr = lookup_template_function (expr, template_args);
  
!   if (TYPE_P (scope))
      {
        expr = (adjust_result_of_qualified_name_lookup 
  	      (expr, scope, current_class_type));
--- 7174,7182 ----
    if (is_template)
      expr = lookup_template_function (expr, template_args);
  
!   if (expr == error_mark_node && complain & tf_error)
!     nested_name_lookup_error (scope, TREE_OPERAND (qualified_id, 1));
!   else if (TYPE_P (scope))
      {
        expr = (adjust_result_of_qualified_name_lookup 
  	      (expr, scope, current_class_type));
*************** tsubst_expr (tree t, tree args, tsubst_f
*** 7595,7606 ****
  	  {
  	    tree scope = DECL_INITIAL (decl);
  	    tree name = DECL_NAME (decl);
  	    
  	    scope = tsubst_expr (scope, args, complain, in_decl);
! 	    do_local_using_decl (lookup_qualified_name (scope,
! 							name, 
! 							/*is_type_p=*/0,
! 							/*complain=*/true));
  	  }
  	else
  	  {
--- 7596,7610 ----
  	  {
  	    tree scope = DECL_INITIAL (decl);
  	    tree name = DECL_NAME (decl);
+ 	    tree decl;
  	    
  	    scope = tsubst_expr (scope, args, complain, in_decl);
! 	    decl = lookup_qualified_name (scope, name,
! 					  /*is_type_p=*/0, /*complain=*/false);
! 	    if (decl == error_mark_node)
! 	      nested_name_lookup_error (scope, name);
! 	    else
! 	      do_local_using_decl (decl);
  	  }
  	else
  	  {
*************** tsubst_copy_and_build (tree t, 
*** 8258,8275 ****
  	       scope is.  */
  	    tmpl = TREE_OPERAND (TREE_OPERAND (member, 1), 0);
  	    args = TREE_OPERAND (TREE_OPERAND (member, 1), 1);
! 	    member = lookup_qualified_name (TREE_OPERAND (member, 0),
! 					    tmpl, 
! 					    /*is_type=*/0,
! 					    /*complain=*/true);
  	    if (BASELINK_P (member))
  	      BASELINK_FUNCTIONS (member) 
  		= build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member),
  			    args);
  	    else
  	      {
! 		error ("`%D' is not a member of `%T'",
! 		       tmpl, TREE_TYPE (object));
  		return error_mark_node;
  	      }
  	  }
--- 8262,8276 ----
  	       scope is.  */
  	    tmpl = TREE_OPERAND (TREE_OPERAND (member, 1), 0);
  	    args = TREE_OPERAND (TREE_OPERAND (member, 1), 1);
! 	    member = lookup_qualified_name (TREE_OPERAND (member, 0), tmpl, 
! 					    /*is_type=*/0, /*complain=*/false);
  	    if (BASELINK_P (member))
  	      BASELINK_FUNCTIONS (member) 
  		= build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member),
  			    args);
  	    else
  	      {
! 		nested_name_lookup_error (TREE_TYPE (object), tmpl);
  		return error_mark_node;
  	      }
  	  }
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.333
diff -c -3 -p -r1.333 semantics.c
*** cp/semantics.c	22 Jul 2003 23:30:20 -0000	1.333
--- cp/semantics.c	25 Jul 2003 10:00:12 -0000
*************** check_multiple_declarators (void)
*** 2248,2253 ****
--- 2248,2269 ----
      error ("multiple declarators in template declaration");
  }
  
+ void
+ nested_name_lookup_error (tree scope, tree name)
+ {
+   if (TYPE_P (scope))
+     {
+       if (!COMPLETE_TYPE_P (scope))
+ 	error ("incomplete type `%T' used in nested name specifier", scope);
+       else
+ 	error ("`%D' is not a member of `%T'", name, scope);
+     }
+   else if (scope != global_namespace)
+     error ("`%D' is not a member of `%D'", name, scope);
+   else
+     error ("`::%D' has not been declared", name);
+ }
+ 	      
  /* ID_EXPRESSION is a representation of parsed, but unprocessed,
     id-expression.  (See cp_parser_id_expression for details.)  SCOPE,
     if non-NULL, is the type or namespace used to explicitly qualify
*************** finish_id_expression (tree id_expression
*** 2307,2323 ****
  	  if (scope && (!TYPE_P (scope) || !dependent_type_p (scope)))
  	    {
  	      /* Qualified name lookup failed, and the qualifying name
! 		 was not a dependent type.  That is always an
! 		 error.  */
! 	      if (TYPE_P (scope) && !COMPLETE_TYPE_P (scope))
! 		error ("incomplete type `%T' used in nested name "
! 		       "specifier",
! 		       scope);
! 	      else if (scope != global_namespace)
! 		error ("`%D' is not a member of `%D'",
! 		       id_expression, scope);
! 	      else
! 		error ("`::%D' has not been declared", id_expression);
  	      return error_mark_node;
  	    }
  	  else if (!scope)
--- 2323,2331 ----
  	  if (scope && (!TYPE_P (scope) || !dependent_type_p (scope)))
  	    {
  	      /* Qualified name lookup failed, and the qualifying name
!       		 was not a dependent type.  That is always an
!       		 error.  */
! 	      nested_name_lookup_error (scope, id_expression);
  	      return error_mark_node;
  	    }
  	  else if (!scope)
Index: testsuite/g++.dg/template/memclass1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/template/memclass1.C,v
retrieving revision 1.1
diff -c -3 -p -r1.1 memclass1.C
*** testsuite/g++.dg/template/memclass1.C	9 May 2003 15:10:28 -0000	1.1
--- testsuite/g++.dg/template/memclass1.C	25 Jul 2003 14:02:07 -0000
*************** template <typename T> struct C
*** 15,18 ****
      typedef typename A<T>::template B<U> X; // { dg-error "declared|invalid" }
  };
  
! C<void> c;			// { dg-error "instantiated" }
--- 15,18 ----
      typedef typename A<T>::template B<U> X; // { dg-error "declared|invalid" }
  };
  
! C<void> c;
// { dg-do compile }

// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 27 Mar 2003 <nathan@codesourcery.com>

// PR 11617: Failed to diagnose missing function.

struct B {};

template <typename T> void Bar ()
{
  T::foo (); // { dg-error "is not a member of" "" }
}

void Foo ()
{
  Bar<B> (); // { dg-error "instantiated" "" }
}

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