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: PR 17413


This patch fixes a problem with our template processing in which we
were too generous with SFINAE.  In paticular, if we deduced a template
parameter to be a local type, we use SFINAE -- contrary to the
standard. 

That caused the error message regression noted in the PR, as well as
correctness issues, as shown by the test cases I added to the PR audit
trail.

The fix for this PR causes g++.dg/template/crash19.C to fail -- as it
should.  The only reason that EDG accepts this code is that they do
not perform overload resolution in integral constant expressions,
which they agree is contrary to the standard.  Analagous code in which
the call to operator* is not within an integral constant expression
fails with EDG.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
 
2004-12-23  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17413
	* pt.c (check_instantiated_args): Remove bogus SFINAE code.

2004-12-23  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17413
	* g++.dg/template/local4.C: New test.
	* g++.dg/template/crash19.C: Add dg-error marker.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.961
diff -c -5 -p -r1.961 pt.c
*** cp/pt.c	23 Dec 2004 16:12:51 -0000	1.961
--- cp/pt.c	23 Dec 2004 19:48:58 -0000
*************** check_instantiated_args (tree tmpl, tree
*** 8924,8936 ****
  	     template arguments.  */
  	  tree nt = no_linkage_check (t, /*relaxed_p=*/false);
  
  	  if (nt)
  	    {
! 	      if (!(complain & tf_error))
! 		/*OK*/;
! 	      else if (TYPE_ANONYMOUS_P (nt))
  		error ("%qT uses anonymous type", t);
  	      else
  		error ("%qT uses local type %qT", t, nt);
  	      result = true;
  	    }
--- 8924,8934 ----
  	     template arguments.  */
  	  tree nt = no_linkage_check (t, /*relaxed_p=*/false);
  
  	  if (nt)
  	    {
! 	      if (TYPE_ANONYMOUS_P (nt))
  		error ("%qT uses anonymous type", t);
  	      else
  		error ("%qT uses local type %qT", t, nt);
  	      result = true;
  	    }
Index: testsuite/g++.dg/template/crash19.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/template/crash19.C,v
retrieving revision 1.2
diff -c -5 -p -r1.2 crash19.C
*** testsuite/g++.dg/template/crash19.C	23 May 2004 22:48:34 -0000	1.2
--- testsuite/g++.dg/template/crash19.C	23 Dec 2004 19:48:58 -0000
*************** struct S 
*** 7,17 ****
  int operator *(const double, const S &); 
  template <class T>
  struct X { 
      enum { SIXTY_FOUR=64 }; 
      struct node {
!       unsigned char *ptr[sizeof(T)*SIXTY_FOUR];
          void d() {}
      };
      node *head; 
  };
  template struct X<int>;
--- 7,17 ----
  int operator *(const double, const S &); 
  template <class T>
  struct X { 
      enum { SIXTY_FOUR=64 }; 
      struct node {
!       unsigned char *ptr[sizeof(T)*SIXTY_FOUR]; // { dg-error "" }
          void d() {}
      };
      node *head; 
  };
  template struct X<int>;
Index: testsuite/g++.dg/template/local4.C
===================================================================
RCS file: testsuite/g++.dg/template/local4.C
diff -N testsuite/g++.dg/template/local4.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/local4.C	23 Dec 2004 19:48:58 -0000
***************
*** 0 ****
--- 1,11 ----
+ // PR c++/17413
+ 
+ template <typename T> void foo() {}
+ 
+ int main () {
+   struct S {};
+   // We do not simply use "local|match" on line 10 because we want to
+   // make sure that "local" appears.
+   // { dg-error "local" "" { target *-*-* } 10 }
+   foo<S> (); // { dg-error "match" } 
+ }


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