Potentially uninitialized local pointer variable used

Hi.

Look at this local pointer variable

 
Node*& searchResult{ SearchPrivateRef(key,root) };


And now look at the SearchPrivateRef() function

1
2
3
4
5
6
7
8
9
10
11
Node*& SearchPrivateRef(T const& key, Node*& current) const
{
	if (current->value == key)
	     return current;

	if (key < current->value)
	     return SearchPrivateRef(key, current->left);

	if (key > current->value)
	     return SearchPrivateRef(key, current->right);
}


This code used to compile before updating Clang. Now it doesn't anymore.

I don't see a scenario where the pointer could result as NULL... but it is a reference and it can't be.

Where's the problem?
What happens if the key is not found? It would appear this would recurse forever.
Last edited on
The SearchPrivateRef() is called after we know for sure the key is in the tree (although it's not mentioned)

Last edited on
that seems useless and repetitive.


You do have some misconceptions.
- "uninitialized" doesn't mean "initialized to NULL". Assigning NULL would be a initialization.
- you've got a reference to a pointer. The reference may be valid, but that says nothing of the pointer. The value stored in the pointer may be NULL.
- the message is probably a warning, not an error (or if it is an error, you may be able to supress it)

Finally, for a better guess, you ought to provide enough code to reproduce your issue.
Topic archived. No new replies allowed.