[cfe-commits] r84974 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaOverload.cpp test/SemaTemplate/template-id-printing.cpp
Douglas Gregor
dgregor at apple.com
Fri Oct 23 15:18:25 PDT 2009
Author: dgregor
Date: Fri Oct 23 17:18:25 2009
New Revision: 84974
URL: http://llvm.org/viewvc/llvm-project?rev=84974&view=rev
Log:
Migrate Sema::ActOnCallExpr to Sema::FixOverloadedFunctionReference,
so that we maintain better source information after template argument
deduction and overloading resolves down to a specific
declaration. Found and dealt with a few more cases that
FixOverloadedFunctionReference didn't cope with.
(Finally) added a test case that puts together this change with the
DeclRefExpr change to (optionally) include nested-name-specifiers and
explicit template argument lists.
Added:
cfe/trunk/test/SemaTemplate/template-id-printing.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=84974&r1=84973&r2=84974&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Oct 23 17:18:25 2009
@@ -2922,13 +2922,7 @@
if (!FDecl)
return ExprError();
- // Update Fn to refer to the actual function selected.
- // FIXME: Use FixOverloadedFunctionReference?
- Expr *NewFn = DeclRefExpr::Create(Context, Qualifier, QualifierRange, FDecl,
- Fn->getLocStart(), FDecl->getType(), false,
- false);
- Fn->Destroy(Context);
- Fn = NewFn;
+ Fn = FixOverloadedFunctionReference(Fn, FDecl);
}
}
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=84974&r1=84973&r2=84974&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Oct 23 17:18:25 2009
@@ -5361,8 +5361,14 @@
Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
if (ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
Expr *NewExpr = FixOverloadedFunctionReference(PE->getSubExpr(), Fn);
- NewExpr->setType(PE->getSubExpr()->getType());
- return NewExpr;
+ PE->setSubExpr(NewExpr);
+ PE->setType(NewExpr->getType());
+ } else if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
+ Expr *NewExpr = FixOverloadedFunctionReference(ICE->getSubExpr(), Fn);
+ assert(Context.hasSameType(ICE->getSubExpr()->getType(),
+ NewExpr->getType()) &&
+ "Implicit cast type cannot be determined from overload");
+ ICE->setSubExpr(NewExpr);
} else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) {
assert(UnOp->getOpcode() == UnaryOperator::AddrOf &&
"Can only take the address of an overloaded function");
@@ -5394,8 +5400,9 @@
return UnOp;
} else if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) {
assert((isa<OverloadedFunctionDecl>(DR->getDecl()) ||
- isa<FunctionTemplateDecl>(DR->getDecl())) &&
- "Expected overloaded function or function template");
+ isa<FunctionTemplateDecl>(DR->getDecl()) ||
+ isa<FunctionDecl>(DR->getDecl())) &&
+ "Expected function or function template");
DR->setDecl(Fn);
E->setType(Fn->getType());
} else if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(E)) {
@@ -5416,6 +5423,12 @@
// FIXME: Don't destroy TID here, since we need its template arguments
// to survive.
// TID->Destroy(Context);
+ } else if (isa<UnresolvedFunctionNameExpr>(E)) {
+ return DeclRefExpr::Create(Context,
+ /*Qualifier=*/0,
+ /*QualifierRange=*/SourceRange(),
+ Fn, E->getLocStart(),
+ Fn->getType(), false, false);
} else {
assert(false && "Invalid reference to overloaded function");
}
Added: cfe/trunk/test/SemaTemplate/template-id-printing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/template-id-printing.cpp?rev=84974&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/template-id-printing.cpp (added)
+++ cfe/trunk/test/SemaTemplate/template-id-printing.cpp Fri Oct 23 17:18:25 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -ast-print %s | FileCheck %s
+namespace N {
+ template<typename T, typename U> void f(U);
+ template<int> void f();
+}
+
+void g() {
+ // CHECK: N::f<int>(3.14
+ N::f<int>(3.14);
+
+ // CHECK: N::f<double>
+ void (*fp)(int) = N::f<double>;
+}
Propchange: cfe/trunk/test/SemaTemplate/template-id-printing.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/SemaTemplate/template-id-printing.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/SemaTemplate/template-id-printing.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list