Before:
```
(lldb) expression some_template_func<int, long>(5)
˄
╰─ error: 'some_template_func' does not name a template but is followed by template arguments
note: Ran expression as 'C++14'.
note: note: non-template declaration found by name lookup
```
After:
```
(lldb) expression some_template_func<int, long>(5)
˄
╰─ error: 'some_template_func' does not name a template but is followed by template arguments
note: Ran expression as 'C++14'.
note: note: non-template declaration found by name lookup
note: Naming template instantiation not yet supported. Template functions can be invoked via their mangled name. E.g., expression _Z3fooIiEvi(5)
```
There isn't a great way to get to the actual function being named (and
its mangled name) since we're just dealing with raw text. So I just
print an example mangled name.
This doesn't work for all template instantiations. E.g.,:
```
(lldb) p f.method<long>(10)
˄ ˄
│ ╰─ error: expected '(' for function-style cast or type construction
╰─ error: no member named 'method' in 'Foo<int>'
note: Ran expression as 'C++14'.
```
This is a consequence of how we construct the AST for template methods.
Once we fix that, this hint will get emitted there too.
Note this will also trigger in cases where no function is being called
(hence I used the defensive phrase "Template functions can be invoked").
rdar://135725807
15 lines
346 B
C++
15 lines
346 B
C++
template <typename T, typename K> static K some_template_func(int x) {
|
|
return (K)x;
|
|
}
|
|
|
|
template <typename T> struct Foo {
|
|
template <typename K> T method(K k) { return (T)k; }
|
|
static T smethod() { return (T)10; }
|
|
};
|
|
|
|
int main() {
|
|
Foo<int> f;
|
|
return some_template_func<int, long>(5) + Foo<int>::smethod() +
|
|
f.method<long>(10);
|
|
}
|