austern     02/09/19 14:03:52

  Modified:    gcc/cp   call.c cp-tree.h tree.c
  Added:       gcc/testsuite/g++.dg/other constref1.C constref2.C
  Log:
  Bug #: 3052788, 2912051
  Fixed overly strict error checking that caused a problem when passing the result of 
a cast expression by const reference.
  
  Revision  Changes    Path
  1.37      +1 -1      gcc3/gcc/cp/call.c
  
  Index: call.c
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/cp/call.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- call.c    2002/08/26 20:08:07     1.36
  +++ call.c    2002/09/19 21:03:46     1.37
  @@ -4089,7 +4089,7 @@
        tree ref_type = totype;
   
        /* If necessary, create a temporary.  */
  -     if (NEED_TEMPORARY_P (convs) || !lvalue_p (expr))
  +     if (NEED_TEMPORARY_P (convs) || !non_cast_lvalue_p (expr))
          {
            tree type = TREE_TYPE (TREE_OPERAND (convs, 0));
            expr = build_target_expr_with_type (expr, type);
  
  
  
  1.70      +1 -0      gcc3/gcc/cp/cp-tree.h
  
  Index: cp-tree.h
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/cp/cp-tree.h,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- cp-tree.h 2002/09/17 22:04:01     1.69
  +++ cp-tree.h 2002/09/19 21:03:47     1.70
  @@ -4227,6 +4227,7 @@
   extern void unshare_base_binfos                      PARAMS ((tree));
   extern int member_p                          PARAMS ((tree));
   extern cp_lvalue_kind real_lvalue_p          PARAMS ((tree));
  +extern int non_cast_lvalue_p                 PARAMS ((tree));
   extern int non_cast_lvalue_or_else           PARAMS ((tree, const char *));
   extern tree build_min                                PARAMS ((enum tree_code, tree,
                                                         ...));
  
  
  
  1.28      +8 -0      gcc3/gcc/cp/tree.c
  
  Index: tree.c
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/cp/tree.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- tree.c    2002/08/26 05:41:02     1.27
  +++ tree.c    2002/09/19 21:03:48     1.28
  @@ -238,6 +238,14 @@
       (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 1) != clk_none);
   }
   
  +int
  +non_cast_lvalue_p (ref)
  +     tree ref;
  +{
  +  return 
  +    (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 0) != clk_none);
  +}
  +
   /* Return nonzero if REF is an lvalue valid for this language;
      otherwise, print an error message and return zero.  */
   
  
  
  
  1.1                  gcc3/gcc/testsuite/g++.dg/other/constref1.C
  
  Index: constref1.C
  ===================================================================
  // { dg-do compile }
  
  // Copyright (C) 2002 Free Software Foundation, Inc.
  // Contributed by Matt Austern 12 Sep 2002 <[EMAIL PROTECTED]>
  
  // Make sure that we can pass a cast-expression as an argument that's
  // passed by const reference.
  
  void bar (const long&)
  { }
  
  void foo (int x)
  {
    bar ((long) x);
  }
  
  
  
  
  1.1                  gcc3/gcc/testsuite/g++.dg/other/constref2.C
  
  Index: constref2.C
  ===================================================================
  // { dg-do compile }
  
  // Copyright (C) 2002 Free Software Foundation, Inc.
  // Contributed by Matt Austern 12 Sep 2002 <[EMAIL PROTECTED]>
  
  // Make sure that we can pass a cast-expression as an argument that's
  // passed to a function template by const reference.
  
  template <class T>
  void bar (const T&)
  { }
  
  void foo (int x)
  {
    bar ((long) x);
  }
  
  
  


Reply via email to