[Issue 17136] New: dictionary get(value, defaultValue) should be nothrow

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Feb 1 13:05:59 PST 2017


https://issues.dlang.org/show_bug.cgi?id=17136

          Issue ID: 17136
           Summary: dictionary get(value, defaultValue) should be nothrow
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: greeenify at gmail.com

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;
}

--


More information about the Digitalmars-d-bugs mailing list