llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Max Winkler (MaxEW707) <details> <summary>Changes</summary> Godbolt for reference: https://godbolt.org/z/ovKjvWc46 I definitely remember this being an extension in older versions of VS around VS 2012 but don't know when MSVC no longer exactly removed support for this extension wholesale. I no longer have work licenses for VS2015 and VS2013. I can confirm that this extension is no longer valid in VS2017, VS2019 and VS2022 under `/permissive` and `/permissive-` I'll continue to spelunk MSDN and see if I can dig up one of old personal VS2015 licenses. --- Full diff: https://github.com/llvm/llvm-project/pull/102851.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaDecl.cpp (+9-5) - (modified) clang/test/SemaCXX/MicrosoftExtensions.cpp (+16-5) ``````````diff diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 694a754646f274..0386560e337618 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -18467,11 +18467,15 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, // the program is ill-formed, except when compiling with MSVC extensions // enabled. if (EltTy->isReferenceType()) { - Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? - diag::ext_union_member_of_reference_type : - diag::err_union_member_of_reference_type) - << NewFD->getDeclName() << EltTy; - if (!getLangOpts().MicrosoftExt) + const bool HaveMSExt = + getLangOpts().MicrosoftExt && + !getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2017); + + Diag(NewFD->getLocation(), + HaveMSExt ? diag::ext_union_member_of_reference_type + : diag::err_union_member_of_reference_type) + << NewFD->getDeclName() << EltTy; + if (!HaveMSExt) NewFD->setInvalidDecl(); } } diff --git a/clang/test/SemaCXX/MicrosoftExtensions.cpp b/clang/test/SemaCXX/MicrosoftExtensions.cpp index 98c19975095bbe..8601f32f064b33 100644 --- a/clang/test/SemaCXX/MicrosoftExtensions.cpp +++ b/clang/test/SemaCXX/MicrosoftExtensions.cpp @@ -3,6 +3,8 @@ // RUN: %clang_cc1 -std=c++11 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify=expected,precxx17 -fms-extensions -fexceptions -fcxx-exceptions -DTEST1 // RUN: %clang_cc1 -std=c++14 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify=expected,precxx17 -fexceptions -fcxx-exceptions -DTEST2 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -fms-compatibility -verify -DTEST3 +// RUN: %clang_cc1 -std=c++17 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fms-compatibility-version=19.00 -DTEST4 +// RUN: %clang_cc1 -std=c++17 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fms-compatibility-version=19.10 -DTEST5 #if TEST1 @@ -384,11 +386,6 @@ void TestSP9() { c3.h(); // Overloaded unary op operand } -union u { - int *i1; - int &i2; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}} -}; - // Property getter using reference. struct SP11 { __declspec(property(get=GetV)) int V; @@ -619,6 +616,20 @@ template<typename T> struct A {}; template<typename T> struct B : A<A<T>> { A<T>::C::D d; }; // expected-warning {{implicit 'typename' is a C++20 extension}} } +#elif TEST4 + +union u { + int *i1; + int &i2; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}} +}; + +#elif TEST5 + +union u { + int *i1; + int &i2; // expected-error {{union member 'i2' has reference type 'int &'}} +}; + #else #error Unknown test mode `````````` </details> https://github.com/llvm/llvm-project/pull/102851 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits