Bug 292228 - Reference not dropped when deducing template arguments
Summary: Reference not dropped when deducing template arguments
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (old) (other bugs)
Version First Reported In: 4.2.60
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-22 21:35 UTC by Nicolás Alvarez
Modified: 2021-03-17 01:35 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolás Alvarez 2012-01-22 21:35:24 UTC
During template argument deduction, KDevelop doesn't drop references. Sample code:

template<typename T> void foo(T x);

int main() {
   int num=42;
   int& ref=num;
   foo(num);
   foo(ref);
}

The first call to 'foo' is marked as a use of 'void foo<int>(int)', and the second as a use of 'void foo<int&>(int&)'. However, both should be foo<int>. According to the C++ specification (N3242=11-0012, section 14.8.2.1), "If P is a reference type, the type referred to by P is used for type deduction."
Comment 1 Nicolás Alvarez 2012-12-08 18:34:18 UTC
This is still a problem in KDevelop 4.4.1
Comment 2 Nicolás Alvarez 2013-01-27 02:00:56 UTC
This seems vaguely related to 1d0079f4.
Comment 3 Justin Zobel 2021-03-09 22:47:59 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.
Comment 4 Nicolás Alvarez 2021-03-17 00:39:40 UTC
This bug applied to the old C++ parser, so surely the new clang-based parser fixed it, right?

Well, I tried it in a current KDevelop with the new clang-based parser and the code above shows both calls to foo as void foo( T x ). Is it dropping references when doing type deduction? Probably (so I'll close the bug as fixed), but I can't really tell, it's not showing any template parameters in the tooltip anymore...

Maybe showing template parameters in the tooltip is a feature that should be brought back.
Comment 5 Aaron Puchert 2021-03-17 01:35:20 UTC
(In reply to Nicolás Alvarez from comment #4)
> Well, I tried it in a current KDevelop with the new clang-based parser and
> the code above shows both calls to foo as void foo( T x ). Is it dropping
> references when doing type deduction? Probably (so I'll close the bug as
> fixed), but I can't really tell, it's not showing any template parameters in
> the tooltip anymore...
Clang at least does the type deduction right. You can convince yourself on the command line by running it with "-fsyntax-only -Xclang -ast-dump".

> Maybe showing template parameters in the tooltip is a feature that should be
> brought back.
Tough. The c-index that we use doesn't contain that information apparently. At least "c-index-test -index-file" on the example code spits out

[startedTranslationUnit]
[enteredMainFile]: <stdin>
[indexDeclaration]: kind: function-template | name: foo | USR: c:@FT@>1#Tfoo#t0.0#v# | lang: C++ | cursor: FunctionDecl=foo:1:27 | loc: 1:27 | semantic-container: [TU] | lexical-container: [TU] | isRedecl: 0 | isDef: 0 | isContainer: 0 | isImplicit: 0
[indexDeclaration]: kind: function | name: main | USR: c:@F@main# | lang: C | cursor: FunctionDecl=main:3:5 (Definition) | loc: 3:5 | semantic-container: [TU] | lexical-container: [TU] | isRedecl: 0 | isDef: 1 | isContainer: 1 | isImplicit: 0
[indexEntityReference]: kind: function-template | name: foo | USR: c:@FT@>1#Tfoo#t0.0#v# | lang: C++ | cursor: DeclRefExpr=foo:1:27 | loc: 6:4 | <parent>:: kind: function | name: main | USR: c:@F@main# | lang: C | container: [main:3:5] | refkind: direct | role: ref call
[indexEntityReference]: kind: function-template | name: foo | USR: c:@FT@>1#Tfoo#t0.0#v# | lang: C++ | cursor: DeclRefExpr=foo:1:27 | loc: 7:4 | <parent>:: kind: function | name: main | USR: c:@F@main# | lang: C | container: [main:3:5] | refkind: direct | role: ref call

As you can see the calls at 6:4 and 7:4 just contain a reference to the function template foo:1:27 (the numbers are line:column). One would think that the magic string tells us something alas another line

   foo(1.0);

produces the same magic string:

[indexEntityReference]: kind: function-template | name: foo | USR: c:@FT@>1#Tfoo#t0.0#v# | lang: C++ | cursor: DeclRefExpr=foo:1:27 | loc: 8:4 | <parent>:: kind: function | name: main | USR: c:@F@main# | lang: C | container: [main:3:5] | refkind: direct | role: ref call