[PATCH] c++/13070: Merge anticipated type attributes

Roger Sayle roger@eyesopen.com
Thu Dec 25 21:04:00 GMT 2003


The following patch is my proposed solution to PR c++/13070, which is
a regression on mainline and 3.3 where we fail to diagnose warnings with
-Wformat.

My revised patch to resolve PR c++/10031, as recommended by Jason,
used the new type of a builtin prototype to define/overwrite the
type of the anticipated built-in function.  This unfortunately has the
effect of also overwriting the type's attributes, including the format
attribute used in implementing -Wformat.  The patch below resolves this
failure, by merging the old type attributes into to new type first.


As Zack is by now aware, duplicate_decls is a twisty-turny labyrinth.
This original hunk was to fix PR c++/10031, which is caused by a
mismatch between the way that nothrow attributes and exception lists
are represented between the front-ends, and the middle-end.
http://gcc.gnu.org/ml/gcc-patches/2003-03/msg01075.html

I think all that's really required is

    TYPE_RAISES_EXCEPTIONS (oldtype) = TYPE_RAISES_EXCEPTIONS (newtype);

but this change could potentially be destabilizing.  The patch below is a
much safer fix, and therefore suitable for gcc 3.3.3.  However, I still
think that it might be a good idea to also apply my original patch for PR
c++/10031 which addressed the deeper issue, of how exception lists are
represented.


The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all langauges except treelang, and regression tested
with a top-level "make -k check" with no new failures.


Ok for mainline?  And the gcc-3_3-branch?



2003-12-25  Roger Sayle  <roger@eyesopen.com>

	PR c++/13070
	* decl.c (duplicate_decls): When setting the type of an anticipated
	declaration, merge the existing type attributes.

	* g++.dg/warn/format3.C: New test case.


Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1164
diff -c -3 -p -r1.1164 decl.c
*** decl.c	19 Dec 2003 23:28:05 -0000	1.1164
--- decl.c	25 Dec 2003 15:23:13 -0000
*************** duplicate_decls (tree newdecl, tree oldd
*** 1261,1267 ****
        /* Even if the types match, prefer the new declarations type
  	 for anticipated built-ins, for exception lists, etc...  */
        else if (DECL_ANTICIPATED (olddecl))
! 	TREE_TYPE (olddecl) = TREE_TYPE (newdecl);

        /* Whether or not the builtin can throw exceptions has no
  	 bearing on this declarator.  */
--- 1261,1272 ----
        /* Even if the types match, prefer the new declarations type
  	 for anticipated built-ins, for exception lists, etc...  */
        else if (DECL_ANTICIPATED (olddecl))
! 	{
! 	  TYPE_ATTRIBUTES (TREE_TYPE (newdecl))
! 	    = (*targetm.merge_type_attributes) (TREE_TYPE (olddecl),
! 						TREE_TYPE (newdecl));
! 	  TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
! 	}

        /* Whether or not the builtin can throw exceptions has no
  	 bearing on this declarator.  */


// PR c++/13070
// { dg-do compile }
// { dg-options "-Wformat" }

extern "C" int printf (const char*, ...);

int main()
{
  printf("%d\n", 1, 1);  // { dg-warning "too many" "printf warning" }
  return 0;
}


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list