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: PRs 10147, 12337, 12344, 12236, 8656


This patch, tested on i686-pc-linux-gnu, fixes the above named PRs.

PR c++/10147 was a confusing error message problem.  Basically, most
uses of "%E" in the C++ front end should be removed; until we do
lowering as a separate phase, any attempt to print expressions is
highly likely to yield inscrutable output in some cases.  A better
solution would be to track column numbers so that we could emit them,
or do caret-style messages.

PR c++/12337 is a simple bug -- we were forgetting to make
new-expressions non-lvalues.

PR c++/12334, c++/12236, c++/8656 are all problems with attributes;
fixed with a simple patch.

Applied on the mainline and on the branch; the branch version is very
slightly tweaked from what's here.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-10-06  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10147
	* call.c (initialize_reference): Tweak error message.
	* cxx-pretty-print.h (cxx_pretty_printer_flags): Remove
	pp_cxx_flag_qualified_id and pp_cxx_flag_global_scope.
	* cxx-pretty-print.c (pp_cxx_id_expression): Always display
	qualified entities using qualified names.
	
	PR c++/12337
	* init.c (build_new_1): Make sure that the expression returned is
	not an lvalue.

	PR c++/12344, c++/12236, c++/8656
	* decl.c (start_function): Do not ignore attributes embedded in a
	function declarator.

2003-10-06  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10147
	* g++.dg/other/error4.C: Update error messages.
	* g++.dg/template/ptrmem4.C: Likewise.
	
	PR c++/12337
	* g++.dg/init/new9.C: New test.
	
	PR c++/12334, c++/12236, c++/8656
	* g++.dg/ext/attrib8.C: New test.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.436
diff -c -5 -p -r1.436 call.c
*** cp/call.c	21 Sep 2003 05:07:16 -0000	1.436
--- cp/call.c	7 Oct 2003 07:01:13 -0000
*************** initialize_reference (tree type, tree ex
*** 6056,6066 ****
            && !real_lvalue_p (expr))
          error ("invalid initialization of non-const reference of "
                 "type '%T' from a temporary of type '%T'",
                 type, TREE_TYPE (expr));
        else
!         error ("could not convert `%E' to `%T'", expr, type);
        return error_mark_node;
      }
  
    /* If DECL is non-NULL, then this special rule applies:
  
--- 6056,6068 ----
            && !real_lvalue_p (expr))
          error ("invalid initialization of non-const reference of "
                 "type '%T' from a temporary of type '%T'",
                 type, TREE_TYPE (expr));
        else
!         error ("invalid initialization of reference of type "
! 	       "'%T' from expression of type '%T'", type, 
! 	       TREE_TYPE (expr));
        return error_mark_node;
      }
  
    /* If DECL is non-NULL, then this special rule applies:
  
Index: cp/cxx-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cxx-pretty-print.c,v
retrieving revision 1.7
diff -c -5 -p -r1.7 cxx-pretty-print.c
*** cp/cxx-pretty-print.c	18 Sep 2003 08:25:12 -0000	1.7
--- cp/cxx-pretty-print.c	7 Oct 2003 07:01:13 -0000
*************** pp_cxx_qualified_id (cxx_pretty_printer 
*** 266,278 ****
  static inline void
  pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
  {
    if (TREE_CODE (t) == OVERLOAD)
      t = OVL_CURRENT (t);
!   if ((TREE_CODE (t) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (t))
!       || (pp_c_base (pp)->flags
!           & (pp_cxx_flag_qualified_id | pp_cxx_flag_global_scope)))
      pp_cxx_qualified_id (pp, t);
    else
      pp_cxx_unqualified_id (pp, t);
  }
  
--- 266,276 ----
  static inline void
  pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
  {
    if (TREE_CODE (t) == OVERLOAD)
      t = OVL_CURRENT (t);
!   if (DECL_P (t) && DECL_CONTEXT (t))
      pp_cxx_qualified_id (pp, t);
    else
      pp_cxx_unqualified_id (pp, t);
  }
  
Index: cp/cxx-pretty-print.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cxx-pretty-print.h,v
retrieving revision 1.4
diff -c -5 -p -r1.4 cxx-pretty-print.h
*** cp/cxx-pretty-print.h	29 Aug 2003 07:00:32 -0000	1.4
--- cp/cxx-pretty-print.h	7 Oct 2003 07:01:13 -0000
*************** Software Foundation, 59 Temple Place - S
*** 28,40 ****
  #define pp_c_base(PP) (&(PP)->c_base)
  
  typedef enum
  {
    /* Ask for an qualified-id.  */
!   pp_cxx_flag_qualified_id = 1 << pp_c_flag_last_bit,
!   pp_cxx_flag_global_scope = 1 << (pp_c_flag_last_bit + 1),
!   pp_cxx_flag_default_argument = 1 << (pp_c_flag_last_bit + 2)
    
  } cxx_pretty_printer_flags;
  
  typedef struct
  {
--- 28,38 ----
  #define pp_c_base(PP) (&(PP)->c_base)
  
  typedef enum
  {
    /* Ask for an qualified-id.  */
!   pp_cxx_flag_default_argument = 1 << pp_c_flag_last_bit
    
  } cxx_pretty_printer_flags;
  
  typedef struct
  {
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1131
diff -c -5 -p -r1.1131 decl.c
*** cp/decl.c	22 Sep 2003 05:09:23 -0000	1.1131
--- cp/decl.c	7 Oct 2003 07:01:19 -0000
*************** start_function (tree declspecs, tree dec
*** 13304,13314 ****
  
        last_function_parms = DECL_ARGUMENTS (decl1);
      }
    else
      {
!       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL);
        /* If the declarator is not suitable for a function definition,
  	 cause a syntax error.  */
        if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
  	return 0;
  
--- 13304,13314 ----
  
        last_function_parms = DECL_ARGUMENTS (decl1);
      }
    else
      {
!       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
        /* If the declarator is not suitable for a function definition,
  	 cause a syntax error.  */
        if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
  	return 0;
  
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.343
diff -c -5 -p -r1.343 init.c
*** cp/init.c	22 Sep 2003 05:09:23 -0000	1.343
--- cp/init.c	7 Oct 2003 07:01:21 -0000
*************** build_new_1 (tree exp)
*** 2274,2284 ****
  	 has been initialized before we start using it.  */
        rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
      }
  
    /* Convert to the final type.  */
!   return build_nop (pointer_type, rval);
  }
  
  static tree
  build_vec_delete_1 (tree base, tree maxindex, tree type,
      special_function_kind auto_delete_vec, int use_global_delete)
--- 2274,2290 ----
  	 has been initialized before we start using it.  */
        rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
      }
  
    /* Convert to the final type.  */
!   rval = build_nop (pointer_type, rval);
! 
!   /* A new-expression is never an lvalue.  */
!   if (real_lvalue_p (rval))
!     rval = build1 (NON_LVALUE_EXPR, TREE_TYPE (rval), rval);
! 
!   return rval;
  }
  
  static tree
  build_vec_delete_1 (tree base, tree maxindex, tree type,
      special_function_kind auto_delete_vec, int use_global_delete)
Index: testsuite/g++.dg/ext/attrib8.C
===================================================================
RCS file: testsuite/g++.dg/ext/attrib8.C
diff -N testsuite/g++.dg/ext/attrib8.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/ext/attrib8.C	7 Oct 2003 07:01:32 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR 8656
+ 
+ extern int * (__attribute__((stdcall)) *fooPtr)( void);
+ int * __attribute__((stdcall)) myFn01( void) { return 0; }
+ 
+ void snafu( void)
+ {
+   fooPtr = myFn01;
+ }
Index: testsuite/g++.dg/init/new9.C
===================================================================
RCS file: testsuite/g++.dg/init/new9.C
diff -N testsuite/g++.dg/init/new9.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/new9.C	7 Oct 2003 07:01:32 -0000
***************
*** 0 ****
--- 1,22 ----
+ // PR 12337
+ 
+ class A {};
+ 
+ template <typename T>
+ class X : public A {
+ public:
+   X(T&);
+ };
+ 
+ class B {
+ public:
+   bool foo(A*);
+   template <typename T>
+   bool foo(T& t) { return foo(new X<T>(t)); }
+ };
+ 
+ int main()
+ {
+   B x, y;
+   x.foo(y);
+ }
Index: testsuite/g++.dg/other/error4.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/other/error4.C,v
retrieving revision 1.1
diff -c -5 -p -r1.1 error4.C
*** testsuite/g++.dg/other/error4.C	21 Mar 2003 15:42:36 -0000	1.1
--- testsuite/g++.dg/other/error4.C	7 Oct 2003 07:01:33 -0000
*************** struct Wrapper {};
*** 9,15 ****
  
  void Foo(int const &); // { dg-error "in passing" "" }
  
  void Baz ()
  {
!   Foo (Wrapper ()); // { dg-error "convert `Wrapper *\\(\\)' to" "" }
  }
--- 9,15 ----
  
  void Foo(int const &); // { dg-error "in passing" "" }
  
  void Baz ()
  {
!   Foo (Wrapper ()); // { dg-error "Wrapper" "" }
  }
Index: testsuite/g++.dg/template/ptrmem4.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/template/ptrmem4.C,v
retrieving revision 1.1
diff -c -5 -p -r1.1 ptrmem4.C
*** testsuite/g++.dg/template/ptrmem4.C	31 Jan 2003 16:28:06 -0000	1.1
--- testsuite/g++.dg/template/ptrmem4.C	7 Oct 2003 07:01:33 -0000
*************** struct SpyExample
*** 14,20 ****
    void inputs();
  };
  
  void SpyExample::ready()
  {
!   queryAliases(inputs);	// { dg-error "convert" }
  }
--- 14,20 ----
    void inputs();
  };
  
  void SpyExample::ready()
  {
!   queryAliases(inputs);	// { dg-error "" }
  }


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