<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Out of line template function declaration not matching any declaration causing null deference at clang/lib/Sema/SemaExpr.cpp:1786"
href="http://llvm.org/bugs/show_bug.cgi?id=21193">21193</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Out of line template function declaration not matching any declaration causing null deference at clang/lib/Sema/SemaExpr.cpp:1786
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rtrieu@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>a.cc:
class Bar {
public:
template <typename U>
void A(U u) {
B(u);
}
};
template <typename U>
void Bar::B(U u);
void test() {
Bar().A(0);
}
commandline:
clang -cc1 -fsyntax-only a.cc
output:
a.cc:10:11: error: out-of-line declaration of 'B' does not match any
declaration in 'Bar'
void Bar::B(U u);
^
a.cc:5:5: error: use of undeclared identifier 'B'
B(u);
^
this->
a.cc:13:9: note: in instantiation of function template specialization
'Bar::A<int>' requested here
Bar().A(0);
^
0 clang 0x00000000011c2495 llvm::sys::PrintStackTrace(_IO_FILE*) +
37
1 clang 0x00000000011c2853
2 libpthread.so.0 0x00007f36a4b73cb0
3 clang 0x0000000001cc821c
clang::Sema::DiagnoseEmptyLookup(clang::Scope*, clang::CXXScopeSpec&,
clang::LookupResult&, clang::CorrectionCandidateCallback&,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>) + 2796
4 clang 0x0000000001df9a0c
5 clang 0x0000000001dee713
6 clang 0x0000000001dee5c4
clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*,
clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool)
+ 644
7 clang 0x0000000001cc336f clang::Sema::ActOnCallExpr(clang::Scope*,
clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool) + 1295
8 clang 0x0000000001eb9f07
9 clang 0x0000000001ea9e79
10 clang 0x0000000001ea9614
11 clang 0x0000000001eb8281
12 clang 0x0000000001ea95c1 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&) + 65
13 clang 0x0000000001ecebae
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool) + 1950
14 clang 0x0000000001ecf9ca
clang::Sema::PerformPendingInstantiations(bool) + 138
15 clang 0x0000000001b3ab6d clang::Sema::ActOnEndOfTranslationUnit()
+ 525
16 clang 0x00000000019a6a98
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 168
17 clang 0x00000000019a34d6 clang::ParseAST(clang::Sema&, bool, bool)
+ 422
18 clang 0x000000000132e329 clang::FrontendAction::Execute() + 57
19 clang 0x00000000013023e3
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 803
20 clang 0x000000000139ab5e
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 2830
21 clang 0x00000000006c7263 cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 675
22 clang 0x00000000006c628a main + 12234
23 libc.so.6 0x00007f36a409d76d __libc_start_main + 237
24 clang 0x00000000006c318d
Stack dump:
0. Program arguments: clang -cc1 -fsyntax-only a.cc
1. <eof> parser at end of file
2. a.cc:4:8: instantiating function definition 'A'
Segmentation fault (core dumped)
Code:
1781 CXXMethodDecl *DepMethod;
1782 if (CurMethod->isDependentContext())
1783 DepMethod = CurMethod;
1784 else if (CurMethod->getTemplatedKind() ==
1785 FunctionDecl::TK_FunctionTemplateSpecialization)
1786 DepMethod =
cast<CXXMethodDecl>(CurMethod->getPrimaryTemplate()->
1787
getInstantiatedFromMemberTemplate()->getTemplatedDecl());
1788 else
1789 DepMethod = cast<CXXMethodDecl>(
1790 CurMethod->getInstantiatedFromMemberFunction());
On line 1786-87,
CurMethod->getPrimaryTemplate()->getInstantiatedFromMemberTemplate() returns a
null pointer, which gets dereferenced.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>