[llvm-bugs] [Bug 48446] New: Incorrect source location for parameters of instantiated member functions and member function templates
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Dec 8 14:21:59 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48446
Bug ID: 48446
Summary: Incorrect source location for parameters of
instantiated member functions and member function
templates
Product: clang
Version: 11.0
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: thonerma at synopsys.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Clang 11 and earlier (I checked back as far as Clang 3.6.0) associate the
source location of (explicit) parameters of instantiated member function and
member function template specializations with the first declaration of those
entities rather than their definition. This behavior is inconsistent with the
source locations used for the implicit 'this' parameter and with parameters of
instantiated specializations of (non-member) function templates.
The following test case illustrates the inconsistency (with exception for
implicit 'this' parameters since the AST dump doesn't include those). The test
case places each parameter declaration on its own line to ensure the AST dump
explicitly includes the line number (line numbers are otherwise omitted in some
cases). For the 'ft<int>' specialization, the source locations displayed for
the ParmVarDecl nodes corresponds to the location of the function template
definition from which the specialization was instantiated. But for the
'ct<int>::mf' and 'ct<int>::mft<int>' specializations, those source locations
correspond to the location of the first declaration of the templates they were
instantiated from rather than the definitions of those templates.
Note also that, in the selected AST dump output for the class specialization
members below, the displayed parameter names do not correspond to the parameter
name at the displayed location. The 'bad_X' names were chosen for the
declarations in order to highlight this discrepancy; the member specializations
use the "good" names associated with the member definitions, but the "bad"
source location associated with their initial declaration.
The incorrect source location is used regardless of whether the parameter has a
dependent or non-dependent type.
The following output was produced using Clang 11 and can also be viewed at
https://godbolt.org/z/v5aWzr.
$ cat t.cpp
template<typename T>
void ft(
T bad_t, // Line 3
int bad_i // Line 4
);
template<typename T>
struct ct {
void mf(
T bad_t, // Line 9
int bad_i // Line 10
);
template<typename U>
void mft(
T bad_t, // Line 14
U bad_u, // Line 15
int bad_i // Line 16
);
};
template<typename T>
void ft(
T t, // Line 21
int i // Line 22
) {}
template<typename T>
void ct<T>::mf(
T t, // Line 26
int i // Line 27
) {}
template<typename T>
template<typename U>
void ct<T>::mft(
T t, // Line 32
U u, // Line 33
int i // Line 34
) {}
void f(ct<int> p) {
ft(0, 1);
p.mf(0, 1);
p.mft(0, 1, 2);
}
$ clang -c -Xclang -ast-dump t.cpp
TranslationUnitDecl
|-FunctionTemplateDecl <line:1:1, line:5:27> line:2:6 ft
...
| `-FunctionDecl <line:20:1, line:23:22> line:20:6 used ft 'void (int, int)'
| |-TemplateArgument type 'int'
| | `-BuiltinType 'int'
| |-ParmVarDecl <line:21:9, col:11> col:11 t 'int':'int'
| |-ParmVarDecl <line:22:14, col:18> col:18 i 'int'
| `-CompoundStmt <line:23:21, col:22>
...
|-ClassTemplateDecl <line:6:1, line:18:1> line:7:8 ct
...
| `-ClassTemplateSpecializationDecl <line:6:1, line:18:1> line:7:8 struct ct
definition
...
| |-CXXMethodDecl <line:25:1, line:28:29> line:8:8 used mf 'void (int, int)'
| | |-ParmVarDecl <line:9:11, col:13> col:13 t 'int':'int'
| | |-ParmVarDecl <line:10:20, col:24> col:24 i 'int'
| | `-CompoundStmt <line:28:28, col:29>
| `-FunctionTemplateDecl <line:12:3, line:17:39> line:13:8 mft
...
| `-CXXMethodDecl <line:31:1, line:35:35> line:13:8 used mft 'void (int,
int, int)'
| |-TemplateArgument type 'int'
| | `-BuiltinType 'int'
| |-ParmVarDecl <line:14:12, col:14> col:14 t 'int':'int'
| |-ParmVarDecl <line:15:21, col:23> col:23 u 'int':'int'
| |-ParmVarDecl <line:16:30, col:34> col:34 i 'int'
| `-CompoundStmt <line:35:34, col:35>
...
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201208/b074c6c0/attachment-0001.html>
More information about the llvm-bugs
mailing list