diff options
author | Logan Chien <tzuhsiang.chien@gmail.com> | 2014-04-13 16:08:24 +0000 |
---|---|---|
committer | Logan Chien <tzuhsiang.chien@gmail.com> | 2014-04-13 16:08:24 +0000 |
commit | af24ad940d4e80a2b79fb23d542743bbb68b6885 (patch) | |
tree | ee819d0997a63f2cbda7cf31a54cd9e043cf34a7 /clang/lib/Sema/SemaCast.cpp | |
parent | adc45bb77b13cb62176cd9c9a3bedd245c5981b1 (diff) | |
download | bcm5719-llvm-af24ad940d4e80a2b79fb23d542743bbb68b6885.tar.gz bcm5719-llvm-af24ad940d4e80a2b79fb23d542743bbb68b6885.zip |
Fix diagnostics for C-style cast to function type.
If the C-style type cast is applied to the overloaded
function and the destination type is function type,
then Clang will crash with assertion failure. For example,
void foo(int);
void foo(int, int);
void bar() {
typedef void (ft)(int);
ft p = (ft)foo;
}
In this case, the overloaded function foo will be cast to
a function type, which should be considered as an error.
But, unfortunately, since the function resolution is using
canonical type, the matched function will be returned, and
result in SEGV.
This patch fixes this issue by removing the assertion and
add some error diagnostics as the one in static_cast.
llvm-svn: 206133
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 5d49225ac4c..41570962a24 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -2097,10 +2097,16 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, DestType, /*Complain*/ true, Found); - - assert(!Fn && "cast failed but able to resolve overload expression!!"); - (void)Fn; - + if (Fn) { + // If DestType is a function type (not to be confused with the function + // pointer type), it will be possible to resolve the function address, + // but the type cast should be considered as failure. + OverloadExpr *OE = OverloadExpr::find(SrcExpr.get()).Expression; + Self.Diag(OpRange.getBegin(), diag::err_bad_cstyle_cast_overload) + << OE->getName() << DestType << OpRange + << OE->getQualifierLoc().getSourceRange(); + Self.NoteAllOverloadCandidates(SrcExpr.get()); + } } else { diagnoseBadCast(Self, msg, (FunctionalStyle ? CT_Functional : CT_CStyle), OpRange, SrcExpr.get(), DestType, ListInitialization); |