]> granicus.if.org Git - clang/commitdiff
In Microsoft mode, force 64 bit hex integer constants to signed type if the LL or...
authorFrancois Pichet <pichet2000@gmail.com>
Tue, 11 Jan 2011 12:23:00 +0000 (12:23 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Tue, 11 Jan 2011 12:23:00 +0000 (12:23 +0000)
For example:

void f(long long){ printf("long long"); }
void f(unsigned long long) { printf("unsigned long long"); }
int main() {
   f(0xffffffffffffffffLL);
}
Will print "long long" using MSVC.

This patch also fixes 16 compile errors related to overloading issues when parsing the MSVC 2008 C++ standard lib.

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

lib/Sema/SemaExpr.cpp
test/Sema/MicrosoftExtensions.cpp [new file with mode: 0644]

index 6f2e2ace86cf73c10f0a9c04bd986dff923c23ba..63afa79f2ae548576cd02d51071a8e76e8d2787c 100644 (file)
@@ -2497,7 +2497,8 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
         // Does it fit in a unsigned long long?
         if (ResultVal.isIntN(LongLongSize)) {
           // Does it fit in a signed long long?
-          if (!Literal.isUnsigned && ResultVal[LongLongSize-1] == 0)
+          if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
+              (getLangOptions().Microsoft && Literal.isLongLong)))
             Ty = Context.LongLongTy;
           else if (AllowUnsigned)
             Ty = Context.UnsignedLongLongTy;
diff --git a/test/Sema/MicrosoftExtensions.cpp b/test/Sema/MicrosoftExtensions.cpp
new file mode 100644 (file)
index 0000000..fea763e
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -fms-extensions -verify 
+
+
+void f(long long);
+void f(int);
+int main()
+{
+  // This is an ambiguous call in standard C++.
+  // This calls f(long long) in Microsoft mode because LL is always signed.
+  f(0xffffffffffffffffLL);
+  f(0xffffffffffffffffi64);
+}