From ad8b22269efc89858f1ef2bf0ba35e9a12f1d26d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 6 Nov 2009 01:14:41 +0000 Subject: [PATCH] If we have a C-style cast, functional cast, or a static_cast to a class type, don't perform the array-to-pointer or function-to-pointer conversions, because we may end up binding a reference to a function or array. With this change, FileCheck now passes -fsyntax-only! llvm-svn: 86211 --- clang/lib/Sema/SemaCXXCast.cpp | 4 ++-- clang/test/SemaCXX/cast-conversion.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp index 76faddaa0384..eb931f33a2bf 100644 --- a/clang/lib/Sema/SemaCXXCast.cpp +++ b/clang/lib/Sema/SemaCXXCast.cpp @@ -388,7 +388,7 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType, return; } - if (!DestType->isLValueReferenceType()) + if (!DestType->isLValueReferenceType() && !DestType->isRecordType()) Self.DefaultFunctionArrayConversion(SrcExpr); unsigned msg = diag::err_bad_cxx_cast_generic; @@ -1104,7 +1104,7 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, if (CastTy->isDependentType() || CastExpr->isTypeDependent()) return false; - if (!CastTy->isLValueReferenceType()) + if (!CastTy->isLValueReferenceType() && !CastTy->isRecordType()) DefaultFunctionArrayConversion(CastExpr); // C++ [expr.cast]p5: The conversions performed by diff --git a/clang/test/SemaCXX/cast-conversion.cpp b/clang/test/SemaCXX/cast-conversion.cpp index cbc24aef28d5..936933d95d1f 100644 --- a/clang/test/SemaCXX/cast-conversion.cpp +++ b/clang/test/SemaCXX/cast-conversion.cpp @@ -19,3 +19,17 @@ int main () { // expected-warning {{expression result unused}} } +template +struct X0 { + X0(const T &); +}; + +template +X0 make_X0(const T &Val) { + return X0(Val); +} + +void test_X0() { + const char array[2]; + make_X0(array); +}