[cfe-commits] r140007 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/MicrosoftCompatibility.cpp
Francois Pichet
pichet2000 at gmail.com
Sun Sep 18 14:37:37 PDT 2011
Author: fpichet
Date: Sun Sep 18 16:37:37 2011
New Revision: 140007
URL: http://llvm.org/viewvc/llvm-project?rev=140007&view=rev
Log:
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.
Added:
cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=140007&r1=140006&r2=140007&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Sep 18 16:37:37 2011
@@ -2866,6 +2866,25 @@
}
}
+ // 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;
}
Added: cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp?rev=140007&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp (added)
+++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp Sun Sep 18 16:37:37 2011
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-compatibility
+
+
+
+namespace ms_conversion_rules {
+
+void f(float a);
+void f(int a);
+
+void test()
+{
+ long a = 0;
+ f((long)0);
+ f(a);
+}
+
+}
+
More information about the cfe-commits
mailing list