public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] d: Don't warn about variables initialized with 'void'
@ 2020-09-10 16:09 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2020-09-10 16:09 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch removes a useless warning in the D front-end.

There is no problem with using `T var = void', it is if the variable
remains uninitialized on first use that a warning should be issued.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-x32.
Committed to mainline.

Regards
Iain.

---
gcc/d/ChangeLog:

	* decl.cc (DeclVisitor::visit (VarDeclaration *)): Don't warn about
	variables initialized with 'void'.
---
 gcc/d/decl.cc | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 8e4237dd056..59844bc8633 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -734,33 +734,24 @@ public:
 	   a check for isVarDeclaration() in DeclarationExp codegen.  */
 	declare_local_var (d);
 
-	if (d->_init)
+	if (d->_init && !d->_init->isVoidInitializer ())
 	  {
 	    tree decl = get_symbol_decl (d);
 
-	    if (!d->_init->isVoidInitializer ())
-	      {
-		ExpInitializer *vinit = d->_init->isExpInitializer ();
-		Expression *ie = initializerToExpression (vinit);
-		tree exp = build_expr (ie);
-
-		/* Maybe put variable on list of things needing destruction.  */
-		if (d->needsScopeDtor ())
-		  {
-		    vec_safe_push (d_function_chain->vars_in_scope, decl);
-		    /* Force a TARGET_EXPR to add the corresponding cleanup.  */
-		    exp = force_target_expr (compound_expr (exp, decl));
-		    TARGET_EXPR_CLEANUP (exp) = build_expr (d->edtor);
-		  }
-
-		add_stmt (exp);
-	      }
-	    else if (d->size (d->loc) != 0)
+	    ExpInitializer *vinit = d->_init->isExpInitializer ();
+	    Expression *ie = initializerToExpression (vinit);
+	    tree exp = build_expr (ie);
+
+	    /* Maybe put variable on list of things needing destruction.  */
+	    if (d->needsScopeDtor ())
 	      {
-		/* Zero-length arrays do not have an initializer.  */
-		warning (OPT_Wuninitialized, "uninitialized variable '%s'",
-			 d->ident ? d->ident->toChars () : "(no name)");
+		vec_safe_push (d_function_chain->vars_in_scope, decl);
+		/* Force a TARGET_EXPR to add the corresponding cleanup.  */
+		exp = force_target_expr (compound_expr (exp, decl));
+		TARGET_EXPR_CLEANUP (exp) = build_expr (d->edtor);
 	      }
+
+	    add_stmt (exp);
 	  }
       }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-10 16:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-10 16:09 [committed] d: Don't warn about variables initialized with 'void' Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).