]> granicus.if.org Git - clang/commitdiff
If we have a C-style cast, functional cast, or a static_cast to a
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 Nov 2009 01:14:41 +0000 (01:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 Nov 2009 01:14:41 +0000 (01:14 +0000)
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!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86211 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCXXCast.cpp
test/SemaCXX/cast-conversion.cpp

index 76faddaa038438e9808c7443b634ffbfbcd86314..eb931f33a2bfe5952196419ab2e24f62b31f2de4 100644 (file)
@@ -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
index cbc24aef28d587ea44aa08d56088d908efc67b6f..936933d95d1fb0eed11e711b94b4c7ca153d00aa 100644 (file)
@@ -19,3 +19,17 @@ int main () {
                        // expected-warning {{expression result unused}}
 }
 
+template<class T>
+struct X0 {
+  X0(const T &);
+};
+
+template<class T>
+X0<T> make_X0(const T &Val) {
+  return X0<T>(Val);
+}
+
+void test_X0() {
+  const char array[2];
+  make_X0(array);
+}