Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Parameter scope nuisance with strftime



This:

Author: Barton E. Schaefer <schaefer@xxxxxxx>
Date:   Sat Apr 25 10:57:44 2015 -0700

    34961: $TZ is implicitly local in builtin strftime (originally workers/34602 from workers/34596)

causes us to start parameter scope (as if creating parameters in a
function) for the strftime builtin in zsh/datetime.

This produces a bogus WARNCREATEGLOBAL warning at the command line:

% strftime -s date %Y%m%d%H%M $EPOCHSECONDS
./zsh:4: scalar parameter date created globally in function

However, the warning code is sort of working correctly: we are indeed
creating a global parameter from a local scope.  What we don't have is a
function on the funcstack --- possibly the warning is redundant in this
case.  I may have been unnecessarily conservative about this when I
created check_warn_create().

pws

diff --git a/Src/params.c b/Src/params.c
index 054fb1f..b2e8897 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2705,30 +2705,18 @@ static void
 check_warn_create(Param pm, const char *pmtype)
 {
     Funcstack i;
-    const char *name;
 
     if (pm->level != 0 || (pm->node.flags & PM_SPECIAL))
 	return;
 
-    name = NULL;
     for (i = funcstack; i; i = i->prev) {
 	if (i->tp == FS_FUNC) {
 	    DPUTS(!i->name, "funcstack entry with no name");
-	    name = i->name;
+	    zwarn("%s parameter %s created globally in function %s",
+		  pmtype, pm->node.nam, i->name);
 	    break;
 	}
     }
-
-    if (name)
-    {
-	zwarn("%s parameter %s created globally in function %s",
-	      pmtype, pm->node.nam, name);
-    }
-    else
-    {
-	zwarn("%s parameter %s created globally in function",
-	      pmtype, pm->node.nam);
-    }
 }
 
 /**/



Messages sorted by: Reverse Date, Date, Thread, Author