[Issue 20918] New: Compiler diagnostic for templates which throw should show the code which throws
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 10 04:11:00 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20918
Issue ID: 20918
Summary: Compiler diagnostic for templates which throw should
show the code which throws
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andrej.mitrovich at gmail.com
Consider this case:
-----
void test2 (T)(T arg)
{
if (arg == 1)
throw new Exception("");
}
void test (T)(T arg)
{
test2(arg);
}
void main (string[] args) nothrow
{
test(1);
}
-----
$ ~/dev/d master * $ dmd test.d
test.d(14): Error: function test.test!int.test is not nothrow
test.d(12): Error: nothrow function D main may throw
This error message makes sense for functions. However for templated functions
we don't necessarily *want* to mark the template function as nothrow. We want
it to be inferred.
In this case, the compiler should give the user a hint, something like:
$ ~/dev/d master * $ dmd test.d
test.d(14): Error: function test.test!int.test is not nothrow
test.d(14): Error: function test.test!int.test2 is not nothrow
test.d(4): Error: function test.test!int.test2 may throw here
Because it's a template the compiler knows why the template is deduced to be a
throwing function. It should tell the user where the offending line is.
--
More information about the Digitalmars-d-bugs
mailing list