[cmake-developers] [CMake 0013786]: function() set(PARENT_SCOPE) buggy: very surprising warn-uninitialized inconsistency for (non-)empty values

Mantis Bug Tracker mantis at public.kitware.com
Wed Dec 12 05:01:20 EST 2012


The following issue has been SUBMITTED. 
====================================================================== 
http://www.itk.org/Bug/view.php?id=13786 
====================================================================== 
Reported By:                Andreas Mohr
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   13786
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   high
Status:                     new
====================================================================== 
Date Submitted:             2012-12-12 05:01 EST
Last Modified:              2012-12-12 05:01 EST
====================================================================== 
Summary:                    function() set(PARENT_SCOPE) buggy: very surprising
warn-uninitialized inconsistency for (non-)empty values
Description: 
I tried to get all my code free of issues,
thus I enabled --warn-uninitialized.
I was very surprised to find that initialization state of a function result
(PARENT_SCOPE) variable is being very negatively influenced by the value of the
passed variable being empty vs. non-empty,
as can be gathered from the sample below warning about result_empty yet properly
*not* warning about result_non_empty.

This should emphatically _not_ be the case - a result variable should *always*
get properly initialized (instantiated) in outer scope, no fr****n' matter which
value it may happen to get assigned.

And it's not a "this variable already exists in outer scope" vs. "does not exist
--> problem" issue: when assigning non-empty values the outer-scope variable
*does* get created, yet not for empty ones --> BUG.

Note that pre-initializing the result var to "" prior to invoking the function
does successfully silence the initialization warning.
And note that doing this initialization with a non-empty value and subsequently
calling the function *does* let the function reset the variable to empty - IOW
the variable *does* get assigned by the function in *this* case - just not if it
didn't exist previously!

Happening on both Win7 2.8.10.2 and RHEL5 2.8.8.....

Severity major and prio high since it's a foundation-shattering inconsistency ;)

Given this bug it's impossible to get one's code warning-free (when making use
of clean result-use-only variable getter functions which happen to return empty
values in certain conditions).
A mere "not succeeding in getting the code warning-free" is a rather benign
concern - some actively disrupting bug scenarios due to this issue might be
conceivable, too.

Thanks!

Steps to Reproduce: 
cmake_minimum_required(VERSION 2.8)

function(getter _result)
  set(result_ "${desired_result}")
  set(${_result} "${result_}" PARENT_SCOPE)
endfunction(getter _result)

#set(result_empty "bye, cruel world") # <---- toggle this!

set(desired_result "")
getter(result_empty)

set(desired_result "non-empty")
getter(result_non_empty)

message("result_empty ${result_empty}, result_non_empty ${result_non_empty}.")

Additional Information: 
$ cmake --warn-uninitialized .
Warn about uninitialized values.
CMake Warning (dev) at
/home/amoh/privat/cmake_tests/bug_function_result_uninitialized_warning/CMakeLists.txt:14:
  uninitialized variable 'result_empty'
This warning is for project developers.  Use -Wno-dev to suppress it.

result_empty , result_non_empty non-empty.
-- Configuring done
-- Generating done

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2012-12-12 05:01 Andreas Mohr   New Issue                                    
======================================================================




More information about the cmake-developers mailing list