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] Stop confusing warning, remove DR295


Hi,
the attached patch removes the implementation of DR295, because that changes
the meaning of existing code. Specifically something like
	template<typename T> void foo (T); //#1
	template<typename T> void foo (T volatile); //#2
for T being 'int ()()' #2 is now chosen, because it is more specialized
than #1 (previously, it would not be deduceable).
Also, I have disabled the warnings about ignoring volatile on a reference,
because we'd get confusing, and incorrect warnings from the attached test case.

I used #if 0 to disable the tests, because that's one of the few (only?)
places where tf_warning is tested for anything. We need better diagnostic
control really.

ok for mainline? booted & tested on i686-pc-linux-gnu.

nathan
--
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

// { dg-do compile }

// Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 9 Sept 2002 <nathan@codesourcery.com>

// During deduction we must not emit diagnostics, until we've deduced
// something. 

template <typename T>
struct Canonicalize
{
  typedef T Canonical;
};
template <typename T>
struct Canonicalize<T const volatile>
{
  typedef T Canonical;
};

template <typename C, typename T>
typename Canonicalize<C &>::Canonical foo (C *p, T *)
{
  return *p;
}
typedef void (*Ptr) ();

template <typename T> int foo (Ptr, T *)
{
  return 0;
}

void Foo () {};

int main ()
{
  return foo (Foo, (void *)0);
}
2002-09-13  Nathan Sidwell  <nathan@codesourcery.com>

	Remove DR 295 implementation.
	* pt.c (check_cv_quals_for_unify): Disable function & method cases.
	* tree.c (cp_build_qualified_type_real): Likewise. Don't warn
	about ignoring volatile qualifiers.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.611
diff -c -3 -p -r1.611 pt.c
*** cp/pt.c	22 Aug 2002 23:22:53 -0000	1.611
--- cp/pt.c	13 Sep 2002 16:16:09 -0000
*************** check_cv_quals_for_unify (strict, arg, p
*** 8570,8577 ****
        /* If the cvr quals of parm will not unify with ARG, they'll be
  	 ignored in instantiation, so we have to do the same here.  */
        if (TREE_CODE (arg) == REFERENCE_TYPE
  	  || TREE_CODE (arg) == FUNCTION_TYPE
! 	  || TREE_CODE (arg) == METHOD_TYPE)
  	parm_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
        if (!POINTER_TYPE_P (arg) &&
  	  TREE_CODE (arg) != TEMPLATE_TYPE_PARM)
--- 8570,8580 ----
        /* If the cvr quals of parm will not unify with ARG, they'll be
  	 ignored in instantiation, so we have to do the same here.  */
        if (TREE_CODE (arg) == REFERENCE_TYPE
+ #if 0     /* Disabled until we decide to implement DR 295. nathan 20020911 */
  	  || TREE_CODE (arg) == FUNCTION_TYPE
! 	  || TREE_CODE (arg) == METHOD_TYPE
! #endif
! 	  || 0)
  	parm_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
        if (!POINTER_TYPE_P (arg) &&
  	  TREE_CODE (arg) != TEMPLATE_TYPE_PARM)
Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.297
diff -c -3 -p -r1.297 tree.c
*** cp/tree.c	31 Aug 2002 02:37:09 -0000	1.297
--- cp/tree.c	13 Sep 2002 16:16:09 -0000
*************** cp_build_qualified_type_real (type, type
*** 569,574 ****
--- 538,548 ----
  {
    tree result;
    int bad_quals = TYPE_UNQUALIFIED;
+   /* We keep bad function qualifiers separate, so that we can decide
+      whether to implement DR 295 or not. DR 295 break existing code,
+      unfortunately. Remove this variable to implement the defect
+      report.  */
+   int bad_func_quals = TYPE_UNQUALIFIED;
  
    if (type == error_mark_node)
      return type;
*************** cp_build_qualified_type_real (type, type
*** 584,589 ****
--- 558,565 ----
  	  || TREE_CODE (type) == METHOD_TYPE))
      {
        bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
+       if (TREE_CODE (type) != REFERENCE_TYPE)
+ 	bad_func_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
        type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
      }
    
*************** cp_build_qualified_type_real (type, type
*** 602,622 ****
      /*OK*/;
    else if (!(complain & (tf_error | tf_ignore_bad_quals)))
      return error_mark_node;
    else
      {
        if (complain & tf_ignore_bad_quals)
   	/* We're not going to warn about constifying things that can't
   	   be constified.  */
   	bad_quals &= ~TYPE_QUAL_CONST;
        if (bad_quals)
   	{
   	  tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
   
!  	  if (!(complain & tf_ignore_bad_quals))
   	    error ("`%V' qualifiers cannot be applied to `%T'",
  		   bad_type, type);
   	  else if (complain & tf_warning)
   	    warning ("ignoring `%V' qualifiers on `%T'", bad_type, type);
   	}
      }
    
--- 578,606 ----
      /*OK*/;
    else if (!(complain & (tf_error | tf_ignore_bad_quals)))
      return error_mark_node;
+   else if (bad_func_quals && !(complain & tf_error))
+     return error_mark_node;
    else
      {
        if (complain & tf_ignore_bad_quals)
   	/* We're not going to warn about constifying things that can't
   	   be constified.  */
   	bad_quals &= ~TYPE_QUAL_CONST;
+       bad_quals |= bad_func_quals;
        if (bad_quals)
   	{
   	  tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
   
!  	  if (!(complain & tf_ignore_bad_quals)
! 	      || bad_func_quals)
   	    error ("`%V' qualifiers cannot be applied to `%T'",
  		   bad_type, type);
+ #if 0     /* Disable for now. Speculative instantiation during
+  	     deduction can get here, and we should not issue
+  	     diagnostics at that time.  nathan 20020911.  */
   	  else if (complain & tf_warning)
   	    warning ("ignoring `%V' qualifiers on `%T'", bad_type, type);
+ #endif
   	}
      }
    
Index: testsuite/g++.dg/template/qualttp20.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/template/qualttp20.C,v
retrieving revision 1.3
diff -c -3 -p -r1.3 qualttp20.C
*** testsuite/g++.dg/template/qualttp20.C	18 Mar 2002 07:39:23 -0000	1.3
--- testsuite/g++.dg/template/qualttp20.C	13 Sep 2002 16:16:16 -0000
*************** struct AS
*** 16,33 ****
  template <typename T> struct B1 : T
  {
    typedef typename T::L __restrict__ r;// { dg-error "`__restrict' qualifiers cannot" "" }
!   typedef typename T::myT __restrict__ p;// { dg-warning "ignoring `__restrict'" "" }
!   
!   typedef typename T::myT volatile *myvolatile; // { dg-warning "ignoring `volatile'" "" }
!   typename T::myT volatile *a;    // { dg-warning "ignoring `volatile'" "" }
!   myvolatile b;			 // { dg-bogus "ignoring `volatile'" "" { xfail *-*-* } }
  };
  template <typename T> struct B2 : T
  {
!   typedef typename T::myT const *myconst;
!   typename T::myT const *a;
!   myconst b;
  };
  
  B1<AS> b1;	// { dg-error "instantiated" "" }
! B2<AS> b2;
--- 16,35 ----
  template <typename T> struct B1 : T
  {
    typedef typename T::L __restrict__ r;// { dg-error "`__restrict' qualifiers cannot" "" }
!   typedef typename T::myT __restrict__ p;// { dg-warning "ignoring `__restrict'" "" { xfail *-*-* } }
! 
!   // The following are DR 295 dependent
!   typedef typename T::myT volatile *myvolatile; // { dg-error "qualifiers" ""  }
!   typename T::myT volatile *a;    // { dg-error "qualifiers" "" }
!   myvolatile b;			 // { dg-error "qualifiers" "" }
  };
  template <typename T> struct B2 : T
  {
!   // The following are DR 295 dependent
!   typedef typename T::myT const *myconst; // { dg-error "qualifiers" "" }
!   typename T::myT const *a; // { dg-error "qualifiers" "" }
!   myconst b; // { dg-error "qualifiers" "" }
  };
  
  B1<AS> b1;	// { dg-error "instantiated" "" }
! B2<AS> b2;      // { dg-error "instantiated" "" }	
Index: testsuite/g++.old-deja/g++.jason/report.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.jason/report.C,v
retrieving revision 1.8
diff -c -3 -p -r1.8 report.C
*** testsuite/g++.old-deja/g++.jason/report.C	11 Mar 2002 21:49:26 -0000	1.8
--- testsuite/g++.old-deja/g++.jason/report.C	13 Sep 2002 16:16:17 -0000
*************** class X{
*** 46,53 ****
  };
  
  typedef int const * bart ();
! typedef bart const * const * bar2; // ok - constifying qualifiers
! typedef bart volatile * const * bar2v; // WARNING - qualifiers
  
  bar2 baz (X::Y y)
  {				// ERROR - in this context
--- 46,54 ----
  };
  
  typedef int const * bart ();
! //The following is DR295 dependant
! typedef bart const * const * bar2; // ERROR - constifying qualifiers
! typedef bart volatile * const * bar2v; // ERROR - qualifiers
  
  bar2 baz (X::Y y)
  {				// ERROR - in this context
Index: testsuite/g++.old-deja/g++.other/qual1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/qual1.C,v
retrieving revision 1.3
diff -c -3 -p -r1.3 qual1.C
*** testsuite/g++.old-deja/g++.other/qual1.C	22 Feb 2002 11:57:50 -0000	1.3
--- testsuite/g++.old-deja/g++.other/qual1.C	13 Sep 2002 16:16:18 -0000
*************** class
*** 10,17 ****
  {
  public:
    func_type *Function;
!   const func_type* function(void) { return Function; } // ok constifying
!   volatile func_type* functionv(void); // WARNING - qualifier
  } action;
  
  void work(const char *source)
--- 10,18 ----
  {
  public:
    func_type *Function;
!   // The following is DR 295 dependent
!   const func_type* function(void) { return Function; } // ERROR - constifying
!   volatile func_type* functionv(void); // ERROR - qualifier
  } action;
  
  void work(const char *source)

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