Bug 17136 – dictionary get(value, defaultValue) should be nothrow
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-02-01T21:05:00Z
Last change time
2017-03-01T11:46:39Z
Assigned to
nobody
Creator
greeenify
Comments
Comment #0 by greeenify — 2017-02-01T21:05:59Z
Consider this simple program:
void main(string[] args) nothrow
{
int[string] dict;
dict["a"] = 1;
auto ret = dict.get("a", 0);
}
it yields the following:
bar.d(6): Error: function 'object.get!(string, int).get' is not nothrow
bar.d(2): Error: nothrow function 'D main' may throw
Failed: ["dmd", "-v", "-c", "-of/tmp/.rdmd-1000/rdmd-bar.d-A4BDC7C9DEEC63B3D5E970F3DA9C439E/objs/bar.o", "bar.d", "-I."]
However the following does compile:
void main(string[] args) nothrow
{
int[string] dict;
dict["a"] = 1;
int ret = 0;
if (auto val = "a" in dict)
ret = *val;
}
Comment #1 by lucia.mcojocaru — 2017-03-01T11:46:39Z
*** This issue has been marked as a duplicate of issue 12647 ***