[cfe-commits] [PATCH] for bug 8230 (invalid casts to function references) for review only
Douglas Gregor
dgregor at apple.com
Fri Oct 1 07:39:44 PDT 2010
On Sep 26, 2010, at 10:09 PM, Faisal Vali wrote:
> http://llvm.org/bugs/show_bug.cgi?id=8230
>
> Doug you had reviewed an earlier rendition of this fix and had made
> some suggestions which I took into account. Before I construct all
> the test cases to conform to my error messages, could I have you
> review this patch - and if you like the direction, I will resubmit a
> final version with a test file with appropriate error messages for the
> test suite. The current test file has to be executed outside the test
> suite.
Some comments...
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td (revision 114784)
+++ include/clang/Basic/DiagnosticSemaKinds.td (working copy)
@@ -2377,6 +2377,12 @@
// C++ casts
// These messages adhere to the TryCast pattern: %0 is an int specifying the
// cast type, %1 is the source type, %2 is the destination type.
+def err_bad_reinterpret_cast_overload : Error<
+ "reinterpret_cast cannot resolve overloads: '%0'">;
I find this wording a little awkward. Perhaps:
"reinterpret_cast cannot resolve overloaded function %0 "
?
@@ -491,8 +509,27 @@
unsigned msg = diag::err_bad_cxx_cast_generic;
if (TryStaticCast(Self, SrcExpr, DestType, /*CStyle*/false, OpRange, msg,
Kind, BasePath) != TC_Success && msg != 0)
- Self.Diag(OpRange.getBegin(), msg) << CT_Static
+ {
+ if ( SrcExpr->getType() == Self.Context.OverloadTy )
+ {
+ OverloadExpr* oe = OverloadExpr::find(SrcExpr).Expression;
+ NestedNameSpecifier* nns = oe->getQualifier();
+ std::string oe_name;
+ if (nns)
+ {
+ llvm::raw_string_ostream os(oe_name);
+ nns->print(os,PrintingPolicy(Self.getLangOptions()));
+ os.flush();
+ }
+ oe_name += oe->getName().getAsString();
+ Self.Diag(OpRange.getBegin(), diag::err_bad_static_cast_overload)
+ << oe_name << DestType << OpRange;
+ NoteAllOverloadCandidates(SrcExpr, Self);
+ }
+ else
+ Self.Diag(OpRange.getBegin(), msg) << CT_Static
<< SrcExpr->getType() << DestType << OpRange;
+ }
else if (Kind == CK_Unknown || Kind == CK_BitCast)
Self.CheckCastAlign(SrcExpr, DestType, OpRange);
}
I don't think we should go through so much effort to format oe_name. Instead, I suggest that we just print the normal name of the function, and then highlight the qualifier range.
Otherwise, looks good!
- Doug
More information about the cfe-commits
mailing list