aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
authorFrancois Pichet <pichet2000@gmail.com>2011-09-18 21:37:37 +0000
committerFrancois Pichet <pichet2000@gmail.com>2011-09-18 21:37:37 +0000
commit1c98d627e5f0b79365d4e64cd4c6795ebed895f3 (patch)
tree001abfc5d66bcdc92643f368651a42a9eae19ae1 /lib/Sema/SemaOverload.cpp
parent416f63e42d4c34a38833a3aa8fa1ebb3c847722b (diff)
In Microsoft mode(-fms-compatibility), prefer an integral conversion to a floating-to-integral conversion if the integral conversion is between types of the same size.
For example: void f(float); void f(int); int main { long a; f(a); } Here, MSVC will call f(int) instead of generating a compile error as clang will do in standard mode. This fixes a few errors when parsing MFC code with clang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140007 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r--lib/Sema/SemaOverload.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index a2ef403618..c084f76a50 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -2866,6 +2866,25 @@ CompareStandardConversionSequences(Sema &S,
}
}
+ // In Microsoft mode, prefer an integral conversion to a
+ // floating-to-integral conversion if the integral conversion
+ // is between types of the same size.
+ // For example:
+ // void f(float);
+ // void f(int);
+ // int main {
+ // long a;
+ // f(a);
+ // }
+ // Here, MSVC will call f(int) instead of generating a compile error
+ // as clang will do in standard mode.
+ if (S.getLangOptions().MicrosoftMode &&
+ SCS1.Second == ICK_Integral_Conversion &&
+ SCS2.Second == ICK_Floating_Integral &&
+ S.Context.getTypeSize(SCS1.getFromType()) ==
+ S.Context.getTypeSize(SCS1.getToType(2)))
+ return ImplicitConversionSequence::Better;
+
return ImplicitConversionSequence::Indistinguishable;
}