Bug 20918 – Compiler diagnostic for templates which throw should show the code which throws

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-10T04:11:00Z
Last change time
2024-12-13T19:09:11Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#17962 →

Comments

Comment #0 by andrej.mitrovich — 2020-06-10T04:11:00Z
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.
Comment #1 by robert.schadek — 2024-12-13T19:09:11Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17962 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB