PATCH: new flag to say when things are synthesized

Brendan Kehoe brendan@zen.org
Wed Nov 8 12:14:00 GMT 2000


Similar to the instantiation patch, this flag helps people know when various
parts of a class have been synthesized quietly for them by the compiler.
(And, in part, help them when they try to figure out when something they
thought was going to be created in fact wasn't, because its base ctor was
non-trivial or whatever...)

Ok?


B

2000-11-08  Brendan Kehoe  <brendan@zen.org>

	* decl2.c (warn_did_synth): New variable.
	(lang_decode_option): Set WARN_DID_SYNTH if -Wdid-synth.
	* lang-options.h: Add -Wdid-synth/-Wno-did-synth.
	* class.c (add_implicitly_declared_members): Use it.
	(check_field_decls): Warn when we mark that we can't synth things.
	* cp-tree.h (warn_did_synth): Add decl.

Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.342
diff -u -p -r1.342 class.c
--- class.c	2000/11/07 22:49:56	1.342
+++ class.c	2000/11/08 16:57:46
@@ -3124,7 +3124,10 @@ add_implicitly_declared_members (t, cant

  	  if (DECL_VINDEX (default_fn))
  	    virtual_dtor = default_fn;
- 
}
+
+ 
   if (warn_did_synth)
+ 
     cp_warning ("synthesized `%D'", default_fn);
+    	}
      }
    else
      /* Any non-implicit destructor is non-trivial.  */
@@ -3136,6 +3139,8 @@ add_implicitly_declared_members (t, cant
        default_fn = implicitly_declare_fn (sfk_constructor, t, 
/*const_p=*/0);
        TREE_CHAIN (default_fn) = implicit_fns;
        implicit_fns = default_fn;
+      if (warn_did_synth)
+ 
cp_warning ("synthesized `%D'", default_fn);
      }

    /* Copy constructor.  */
@@ -3148,6 +3153,8 @@ add_implicitly_declared_members (t, cant
  	 
		 /*const_p=*/!cant_have_const_cctor);
        TREE_CHAIN (default_fn) = implicit_fns;
        implicit_fns = default_fn;
+      if (warn_did_synth)
+ 
cp_warning ("synthesized `%D'", default_fn);
      }

    /* Assignment operator.  */
@@ -3158,6 +3165,9 @@ add_implicitly_declared_members (t, cant
  	 
		 /*const_p=*/!cant_have_const_assignment);
        TREE_CHAIN (default_fn) = implicit_fns;
        implicit_fns = default_fn;
+
+      if (warn_did_synth)
+ 
cp_warning ("synthesized `%D'", default_fn);
      }

    /* Now, hook all of the new functions on to TYPE_METHODS,
@@ -3371,14 +3381,29 @@ check_field_decl (field, t, cant_have_co
  	}

        if (!TYPE_HAS_CONST_INIT_REF (type))
- 
*cant_have_const_ctor = 1;
+ 
{
+ 
   *cant_have_const_ctor = 1;
+ 
   if (warn_did_synth)
+ 
     cp_warning ("cannot synthesize default copy constructor for `%T'",
+ 
		type);
+ 
}

        if (!TYPE_HAS_CONST_ASSIGN_REF (type))
- 
*no_const_asn_ref = 1;
+ 
{
+ 
   *no_const_asn_ref = 1;
+ 
   if (warn_did_synth)
+ 
     cp_warning ("cannot synthesize default assignment operator for `%T'",
+ 
		type);
+ 
}

        if (TYPE_HAS_CONSTRUCTOR (type)
  	  && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
- 
*cant_have_default_ctor = 1;
+ 
{
+ 
   *cant_have_default_ctor = 1;
+ 
   if (warn_did_synth)
+ 
     cp_warning ("cannot synthesize default constructor for `%T'",
+ 
		type);
+ 
}
      }
    if (DECL_INITIAL (field) != NULL_TREE)
      {
@@ -3567,6 +3592,9 @@ check_field_decls (t, access_decls, empt
  	     members.  */
  	  *cant_have_default_ctor_p = 1;
  	  TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
+ 
   if (warn_did_synth)
+ 
     cp_warning ("cannot synthesize default constructor for reference 
type `%T'",
+ 
		t);

  	  if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
  	    {
@@ -3603,6 +3631,9 @@ check_field_decls (t, access_decls, empt
  	     only way to initialize nonstatic const and reference
  	     members.  */
  	  *cant_have_default_ctor_p = 1;
+ 
   if (warn_did_synth)
+ 
     cp_warning ("cannot synthesize default constructor for type `%T' 
with const member(s)",
+ 
		t);
  	  TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;

  	  if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.539
diff -u -p -r1.539 cp-tree.h
--- cp-tree.h	2000/10/31 08:43:16	1.539
+++ cp-tree.h	2000/11/08 16:58:02
@@ -1103,6 +1103,9 @@ extern int warn_old_style_cast;

  extern int warn_reorder;

+/* Non-zero means warn when we synthesize a ctor/dtor/operator.  */
+extern int warn_did_synth;
+
  /* Nonzero means to treat bitfields as unsigned unless they say 
`signed'.  */

  extern int flag_signed_bitfields;
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.409
diff -u -p -r1.409 decl2.c
--- decl2.c	2000/11/08 14:03:29	1.409
+++ decl2.c	2000/11/08 16:58:18
@@ -315,6 +315,9 @@ int warn_reorder;
  /* Non-zero means warn when synthesis behavior differs from Cfront's.  */
  int warn_synth;

+/* Non-zero means warn when we synthesize a ctor/dtor/operator.  */
+int warn_did_synth;
+
  /* Non-zero means warn when we convert a pointer to member function
     into a pointer to (void or function).  */
  int warn_pmf2ptr = 1;
@@ -755,6 +770,8 @@ lang_decode_option (argc, argv)
  	warn_reorder = setting;
        else if (!strcmp (p, "synth"))
  	warn_synth = setting;
+      else if (!strcmp (p, "did-synth"))
+ 
warn_did_synth = setting;
        else if (!strcmp (p, "pmf-conversions"))
  	warn_pmf2ptr = setting;
        else if (!strcmp (p, "effc++"))
Index: lang-options.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/lang-options.h,v
retrieving revision 1.36
diff -u -p -r1.36 lang-options.h
--- lang-options.h	2000/06/06 20:11:40	1.36
+++ lang-options.h	2000/11/08 16:58:19
@@ -126,6 +126,8 @@ DEFINE_LANG_NAME ("C++")
    { "-Wno-reorder", "" },
    { "-Wsynth", "Warn when synthesis behaviour differs from Cfront" },
    { "-Wno-synth", "" },
+  { "-Wdid-synth", "Warn when we synthesize a ctor/dtor/operator" },
+  { "-Wno-did-synth", "" },
    { "-Wpmf-conversions", "" },
    { "-Wno-pmf-conversions", "Don't warn when type converting pointers 
to member functions" },
    { "-Weffc++", "Warn about violations of Effective C++ style rules" },


-- 
Brendan Kehoe

CTO of Nobie.com ( http://www.nobie.com/ )
        -- Finally true Net marketing in .ie



More information about the Gcc-bugs mailing list