[cfe-commits] r127148 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CXX/over/over.over/p2-resolve-single-template-id.cpp
Douglas Gregor
dgregor at apple.com
Sun Mar 6 18:05:23 PST 2011
Author: dgregor
Date: Sun Mar 6 20:05:23 2011
New Revision: 127148
URL: http://llvm.org/viewvc/llvm-project?rev=127148&view=rev
Log:
Produce a diagnostic for unused overloaded expressions, from Faisal Vali!
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127148&r1=127147&r2=127148&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Mar 6 20:05:23 2011
@@ -3911,8 +3911,31 @@
if (DiagnoseUnexpandedParameterPack(FullExpr))
return ExprError();
+ // 13.4.1 ... An overloaded function name shall not be used without arguments
+ // in contexts other than those listed [i.e list of targets].
+ //
+ // void foo(); void foo(int);
+ // template<class T> void fooT(); template<class T> void fooT(int);
+
+ // Therefore these should error:
+ // foo;
+ // fooT<int>;
+
+ if (FullExpr->getType() == Context.OverloadTy) {
+ if (!ResolveSingleFunctionTemplateSpecialization(FullExpr,
+ /* Complain */ false)) {
+ OverloadExpr* OvlExpr = OverloadExpr::find(FullExpr).Expression;
+ Diag(FullExpr->getLocStart(), diag::err_addr_ovl_ambiguous)
+ << OvlExpr->getName();
+ NoteAllOverloadCandidates(OvlExpr);
+ return ExprError();
+ }
+ }
+
+
IgnoredValueConversions(FullExpr);
CheckImplicitConversions(FullExpr);
+
return MaybeCreateExprWithCleanups(FullExpr);
}
Modified: cfe/trunk/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/over/over.over/p2-resolve-single-template-id.cpp?rev=127148&r1=127147&r2=127148&view=diff
==============================================================================
--- cfe/trunk/test/CXX/over/over.over/p2-resolve-single-template-id.cpp (original)
+++ cfe/trunk/test/CXX/over/over.over/p2-resolve-single-template-id.cpp Sun Mar 6 20:05:23 2011
@@ -22,6 +22,36 @@
} // End namespace
+namespace DontAllowUnresolvedOverloadedExpressionInAnUnusedExpression
+{
+ void one() { }
+ template<class T> void oneT() { }
+
+ void two() { } //expected-note 2{{candidate}}
+ void two(int) { } //expected-note 2{{candidate}}
+ template<class T> void twoT() { } //expected-note 2{{candidate}}
+ template<class T> void twoT(T) { } //expected-note 2{{candidate}}
+
+ void check()
+ {
+ one; // expected-warning {{expression result unused}}
+ two; // expected-error{{address of overloaded function}}
+ oneT<int>; // expected-warning {{expression result unused}}
+ twoT<int>; // expected-error {{address of overloaded function}}
+ }
+
+ // check the template function case
+ template<class T> void check()
+ {
+ one; // expected-warning {{expression result unused}}
+ two; // expected-error{{address of overloaded function}}
+ oneT<int>; // expected-warning {{expression result unused}}
+ twoT<int>; // expected-error {{address of overloaded function}}
+
+ }
+
+}
+
template<typename T>
void twoT() { }
template<typename T, typename U>
@@ -45,6 +75,7 @@
int main()
{
+
{ static_cast<void>(one); }
{ (void)(one); }
{ static_cast<void>(oneT<int>); }
More information about the cfe-commits
mailing list