bugmake - Bugs: bug #13886, eval uses old value of variable,...

 
 

bug #13886: eval uses old value of variable, not current value

Submitted by:  David Taylor <taylor>
Submitted on:  Fri 22 Jul 2005 06:34:12 PM UTC  
 
Severity: 3 - NormalItem Group: Bug
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: 4.0Operating System: POSIX-Based
Fixed Release: NoneTriage Status: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 27 Jul 2005 05:47:58 PM UTC, comment #2:

As you say, this is intended. It happens because the variable reference $(FOO) in the function is evaluated by the call function, before being passed to eval, and at that time the value of FOO is 42. If you use the classic debug option for call:

$(warning $(call assign_and_echo,49,b))

you'll see that instead of a reference to $(FOO) in the command script the value 42 has already been substituted.

You need to escape this reference, like this:

define assign_and_echo
FOO := $(1)

$(2): ; @echo target is $(2) and FOO is $$(FOO)
endef

if you want it to be deferred.

I'm not exactly sure where to add clarifying comments about this into the manual: the unfortunate fact is that the interactions between functions like call, eval, etc. can be very complex.

Paul D. Smith <psmith>
Project Administrator
Sat 23 Jul 2005 12:57:19 PM UTC, comment #1:

Not a bug -- intended behavior. Perhaps the manual should
have a clarifying sentence or two.

David Taylor <taylor>
Fri 22 Jul 2005 06:34:12 PM UTC, original submission:

Consider the attached makefile. Do a make of the 'all' target.
I feel that the values printed for FOO should be 56, 49, 35. Instead you see 56, 42, 35.

The second user defined function evals to the wrong thing!

You have the function:

define assign_and_echo
FOO := $(1)

$(2):
@echo target is $(2) and FOO is $(FOO)
endef

It in invoked thusly:

$(eval $(call assign_and_echo,49,b))

with an existing old value of 42 for FOO.

$eval should effectively replace that with:

FOO := 49

b:
@echo target is b and FOO is 49

But, you will instead see 42 printed (the old value).

David Taylor <taylor>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #3261:  eval.mk added by taylor (451B - application/octet-stream - makefile)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 4 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Wed 27 Jul 2005 05:47:58 PM UTCpsmithStatusNone=>Not A Bug
  Open/ClosedOpen=>Closed
Fri 22 Jul 2005 06:34:12 PM UTCtaylorAttached File-=>Added eval.mk, #2732
  Carbon-Copy-=>Added -unavailable-

Back to the top


Powered by Savane 3.1-cleanup1