D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6500 - Show template instantiation values too
Summary: Show template instantiation values too
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-08-15 14:30 UTC by bearophile_hugs
Modified: 2021-01-24 05:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-08-15 14:30:20 UTC
This enhancement is of minor priority.

A small C++ program:


template <int x>
int foo(int y) {
    unsigned int z = 10;
    return y < z;
}
int main() {
    foo<5>(6);
    return 0;
}


On it G++ 4.6 shows a warning, and it shows "x = 5" (the template instantiation value) too:

...>g++ -Wall test.cpp -o test
test.cpp: In function 'int foo(int) [with int x = 5]':
test.cpp:7:13:   instantiated from here
test.cpp:4:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]



I'd like DMD to do something similar, and show the template instatiation values when it gives warnings:


int foo(int x)() {
    return x;
    static if (x > 10)
        return x + 1;
}
int main() {
    return foo!(12)();
}


DMD 2.054 gives:
test.d(4): Warning: statement is not reachable


This enhancement request applies to warnings like the signed/unsigned one in pull 119 too:
https://github.com/D-Programming-Language/dmd/pull/119
Comment 1 mhh 2021-01-24 05:45:00 UTC
The compiler does tell you when something broke inside a template (*and* give you parameters)

Up to      2.063  : Failure with output:
-----
onlineapp.d(2): Error: static assert  (0) is false
onlineapp.d(5):        instantiated from here: foo!(12)