Patchwork Various minor C++ PATCHes

login
register
mail settings
Submitter Jason Merrill
Date Oct. 1, 2012, 11:55 p.m.
Message ID <506A2D8C.7070708@redhat.com>
Download mbox | patch
Permalink /patch/188368/
State New
Headers show

Comments

Jason Merrill - Oct. 1, 2012, 11:55 p.m.
1) I wanted a lang-specific flag for my thread_local work, so I took the 
one away from __PRETTY_FUNCTION__, which really doesn't need it.

2) I didn't end up wanting to use a flag in DECL_LANG_SPECIFIC, but it
still makes sense to check for appropriate tree codes in DECL_FRIEND_P 
and DECL_ANTICIPATED.

3) DECL_NONTRIVIALLY_INITIALIZED_P currently means "has a user-written 
initializer" and it would be more useful to me if it actually meant "has 
non-trivial initialization" so that a non-trivial default constructor 
counts even if there is nothing written in the variable declaration. 
The one existing reader of this flag seems to agree with me.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 2574183057d9bc473146de7e7daad0a393e3da66
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 1 09:36:09 2012 -0400

    	* decl.c (check_initializer): Set DECL_NONTRIVIALLY_INITIALIZED_P
    	for a constructor call.
    	(decl_jump_unsafe): So don't bother checking
    	type_has_nontrivial_default_init.
    	* call.c (set_up_extended_ref_temp): Set
    	DECL_NONTRIVIALLY_INITIALIZED_P.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 6f7e346..d0492d8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8792,6 +8792,9 @@  set_up_extended_ref_temp (tree decl, tree expr, VEC(tree,gc) **cleanups,
   TARGET_EXPR_INITIAL (expr)
     = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups);
 
+  /* Any reference temp has a non-trivial initializer.  */
+  DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
+
   /* If the initializer is constant, put it in DECL_INITIAL so we get
      static initialization and use in constant expressions.  */
   init = maybe_constant_init (expr);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index e4f3761..bfe7ad7 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2271,12 +2271,13 @@  struct GTY((variable_size)) lang_decl {
 
 /* Nonzero for a VAR_DECL means that the variable's initialization (if
    any) has been processed.  (In general, DECL_INITIALIZED_P is
-   !DECL_EXTERN, but static data members may be initialized even if
+   !DECL_EXTERNAL, but static data members may be initialized even if
    not defined.)  */
 #define DECL_INITIALIZED_P(NODE) \
    (TREE_LANG_FLAG_1 (VAR_DECL_CHECK (NODE)))
 
-/* Nonzero for a VAR_DECL iff an explicit initializer was provided.  */
+/* Nonzero for a VAR_DECL iff an explicit initializer was provided
+   or a non-trivial constructor is called.  */
 #define DECL_NONTRIVIALLY_INITIALIZED_P(NODE)	\
    (TREE_LANG_FLAG_3 (VAR_DECL_CHECK (NODE)))
 
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d4c78e1..d0933ef 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2679,8 +2679,7 @@  decl_jump_unsafe (tree decl)
 
   type = strip_array_types (type);
 
-  if (type_has_nontrivial_default_init (TREE_TYPE (decl))
-      || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
+  if (DECL_NONTRIVIALLY_INITIALIZED_P (decl))
     return 2;
 
   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
@@ -5581,6 +5580,11 @@  check_initializer (tree decl, tree init, int flags, VEC(tree,gc) **cleanups)
 	{
 	  init_code = build_aggr_init_full_exprs (decl, init, flags);
 
+	  /* A constructor call is a non-trivial initializer even if
+	     it isn't explicitly written.  */
+	  if (TREE_SIDE_EFFECTS (init_code))
+	    DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
+
 	  /* If this is a constexpr initializer, expand_default_init will
 	     have returned an INIT_EXPR rather than a CALL_EXPR.  In that
 	     case, pull the initializer back out and pass it down into