curdeius created this revision. curdeius added reviewers: mstorsjo, thakis, phosek. Herald added a subscriber: dexonsmith. curdeius requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
As of MSVC 19.28 (2019 Update 8), integral conversion is no longer preferred over floating-to-integral, and so MSVC is more standard conformant and will generate a compiler error on ambiguous call. Cf. https://godbolt.org/z/E8xsdqKsb. Initially found during the review of D99641 <https://reviews.llvm.org/D99641>. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D99663 Files: clang/include/clang/Basic/LangOptions.h clang/lib/Sema/SemaOverload.cpp clang/test/SemaCXX/MicrosoftCompatibility.cpp Index: clang/test/SemaCXX/MicrosoftCompatibility.cpp =================================================================== --- clang/test/SemaCXX/MicrosoftCompatibility.cpp +++ clang/test/SemaCXX/MicrosoftCompatibility.cpp @@ -1,3 +1,5 @@ +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.28 +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.27 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00 @@ -28,12 +30,20 @@ void f(float a); void f(int a); +#if _MSC_VER >= 1928 +// expected-note@-3 2 {{candidate function}} +// expected-note@-3 2 {{candidate function}} +#endif void test() { long a = 0; f((long)0); - f(a); + f(a); +#if _MSC_VER >= 1928 +// expected-error@-3 {{call to 'f' is ambiguous}} +// expected-error@-3 {{call to 'f' is ambiguous}} +#endif } } Index: clang/lib/Sema/SemaOverload.cpp =================================================================== --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -4106,7 +4106,7 @@ } } - // In Microsoft mode, prefer an integral conversion to a + // In Microsoft mode (below 19.28), prefer an integral conversion to a // floating-to-integral conversion if the integral conversion // is between types of the same size. // For example: @@ -4118,7 +4118,9 @@ // } // Here, MSVC will call f(int) instead of generating a compile error // as clang will do in standard mode. - if (S.getLangOpts().MSVCCompat && SCS1.Second == ICK_Integral_Conversion && + if (S.getLangOpts().MSVCCompat && + !S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2019_8) && + SCS1.Second == ICK_Integral_Conversion && SCS2.Second == ICK_Floating_Integral && S.Context.getTypeSize(SCS1.getFromType()) == S.Context.getTypeSize(SCS1.getToType(2))) Index: clang/include/clang/Basic/LangOptions.h =================================================================== --- clang/include/clang/Basic/LangOptions.h +++ clang/include/clang/Basic/LangOptions.h @@ -124,6 +124,7 @@ MSVC2017_5 = 1912, MSVC2017_7 = 1914, MSVC2019 = 1920, + MSVC2019_8 = 1928, }; enum SYCLMajorVersion {
Index: clang/test/SemaCXX/MicrosoftCompatibility.cpp =================================================================== --- clang/test/SemaCXX/MicrosoftCompatibility.cpp +++ clang/test/SemaCXX/MicrosoftCompatibility.cpp @@ -1,3 +1,5 @@ +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.28 +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.27 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00 @@ -28,12 +30,20 @@ void f(float a); void f(int a); +#if _MSC_VER >= 1928 +// expected-note@-3 2 {{candidate function}} +// expected-note@-3 2 {{candidate function}} +#endif void test() { long a = 0; f((long)0); - f(a); + f(a); +#if _MSC_VER >= 1928 +// expected-error@-3 {{call to 'f' is ambiguous}} +// expected-error@-3 {{call to 'f' is ambiguous}} +#endif } } Index: clang/lib/Sema/SemaOverload.cpp =================================================================== --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -4106,7 +4106,7 @@ } } - // In Microsoft mode, prefer an integral conversion to a + // In Microsoft mode (below 19.28), prefer an integral conversion to a // floating-to-integral conversion if the integral conversion // is between types of the same size. // For example: @@ -4118,7 +4118,9 @@ // } // Here, MSVC will call f(int) instead of generating a compile error // as clang will do in standard mode. - if (S.getLangOpts().MSVCCompat && SCS1.Second == ICK_Integral_Conversion && + if (S.getLangOpts().MSVCCompat && + !S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2019_8) && + SCS1.Second == ICK_Integral_Conversion && SCS2.Second == ICK_Floating_Integral && S.Context.getTypeSize(SCS1.getFromType()) == S.Context.getTypeSize(SCS1.getToType(2))) Index: clang/include/clang/Basic/LangOptions.h =================================================================== --- clang/include/clang/Basic/LangOptions.h +++ clang/include/clang/Basic/LangOptions.h @@ -124,6 +124,7 @@ MSVC2017_5 = 1912, MSVC2017_7 = 1914, MSVC2019 = 1920, + MSVC2019_8 = 1928, }; enum SYCLMajorVersion {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits