[LLVMdev] Adding DenseMap::FindAndConstruct with a default value
eli.friedman at gmail.com
Fri Jun 6 01:39:06 PDT 2008
On Fri, Jun 6, 2008 at 12:27 AM, Matthijs Kooijman <matthijs at stdin.nl> wrote:
>> Assuming the default value is not a valid entry in your map (for instance,
>> if you're using pointers), you can do:
>> Foo& entry = DenseMap[Key]
>> if (entry == DefaultValue)
>> entry = constructNewValue();
> The problem here is that the DefaultValue is undefined. However, Chris
> suggested that the default value, ValueT(), is not undefined but simply zero.
This is correct; from the standard: "The expression T(), where T is a
simple-type-specifier (188.8.131.52) for a non-array complete object type
or the (possibly cv-qualified) void type, creates an rvalue of the
specified type, which is value-initialized." (Section 5.2.3
[expr.type.conv] in the C++0x draft standard; I don't have the
published standard on hand.) And value-initialization is defined to be
zero-initialization for scalar types. (Section 8.5 [dcl.init] in the
> However, on IRC someone was quite positive that it would become undefined.
The reason this is kind of confusing is that in a lot of places, the
standard says something along the lines of "if this object is a
non-POD type, value-initialize it; otherwise, leave it uninitialized"
(examples include automatic variables and class members).
More information about the llvm-dev