<div dir="ltr">As noted in PR27337, this only occurs in one WTL sample, and we have no evidence that it actually occurs in real code. Have you seen uses of this in the wild? We generally don't want to add compatibility for MSVC bugs unless there's some real-world motivation.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 2:21 AM, Dmitry Polukhin via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dpolukhin<br>
Date: Tue Apr 26 04:21:17 2016<br>
New Revision: 267534<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=267534&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=267534&view=rev</a><br>
Log:<br>
[MSVC] PR27337: allow static_cast from private base to derived for WTL<br>
<br>
MSVC doesn't report even warning for cast from private base class to<br>
derived.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D19477" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19477</a><br>
<br>
Added:<br>
    cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp   (with props)<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/Sema/SemaCast.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 26 04:21:17 2016<br>
@@ -5764,6 +5764,9 @@ def err_static_downcast_via_virtual : Er<br>
   "cannot cast %0 to %1 via virtual base %2">;<br>
 def err_downcast_from_inaccessible_base : Error<<br>
   "cannot cast %select{private|protected}2 base class %1 to %0">;<br>
+def ext_ms_downcast_from_inaccessible_base : ExtWarn<<br>
+  "casting from %select{private|protected}2 base class %1 to derived class %0 is a Microsoft extension">,<br>
+  InGroup<MicrosoftCast>;<br>
 def err_upcast_to_inaccessible_base : Error<<br>
   "cannot cast %0 to its %select{private|protected}2 base class %1">;<br>
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaCast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Apr 26 04:21:17 2016<br>
@@ -1344,10 +1344,11 @@ TryStaticDowncast(Sema &Self, CanQualTyp<br>
   }<br>
<br>
   if (!CStyle) {<br>
-    switch (Self.CheckBaseClassAccess(OpRange.getBegin(),<br>
-                                      SrcType, DestType,<br>
-                                      Paths.front(),<br>
-                                diag::err_downcast_from_inaccessible_base)) {<br>
+    unsigned Diag = Self.getLangOpts().MSVCCompat<br>
+                        ? diag::ext_ms_downcast_from_inaccessible_base<br>
+                        : diag::err_downcast_from_inaccessible_base;<br>
+    switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType, DestType,<br>
+                                      Paths.front(), Diag)) {<br>
     case Sema::AR_accessible:<br>
     case Sema::AR_delayed:     // be optimistic<br>
     case Sema::AR_dependent:   // be optimistic<br>
<br>
Added: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267534&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267534&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (added)<br>
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp Tue Apr 26 04:21:17 2016<br>
@@ -0,0 +1,40 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s<br>
+// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s<br>
+<br>
+// Minimal reproducer.<br>
+class A {};<br>
+class B : A {}; // expected-note 2 {{implicitly declared private here}}<br>
+<br>
+B* foo(A* p) {<br>
+  return static_cast<B*>(p);<br>
+#ifdef NO_MS_COMPATIBILITY<br>
+  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}<br>
+#else<br>
+  // expected-warning@-4 {{casting from private base class 'A' to derived class 'B' is a Microsoft extension}}<br>
+#endif<br>
+}<br>
+<br>
+A* bar(B* p) {<br>
+  return static_cast<A*>(p); // expected-error {{cannot cast 'B' to its private base class 'A'}}<br>
+}<br>
+<br>
+// from atlframe.h<br>
+template <class T><br>
+class CUpdateUI {<br>
+public:<br>
+  CUpdateUI() {<br>
+    T* pT = static_cast<T*>(this);<br>
+#ifdef NO_MS_COMPATIBILITY<br>
+    // expected-error@-2 {{cannot cast private base class}}<br>
+#else<br>
+    // expected-warning@-4 {{casting from private base class 'CUpdateUI<CMDIFrame>' to derived class 'CMDIFrame' is a Microsoft extension}}<br>
+#endif<br>
+  }<br>
+};<br>
+<br>
+// from sample WTL/MDIDocVw (mainfrm.h<br>
+class CMDIFrame : CUpdateUI<CMDIFrame> {};<br>
+// expected-note@-1 {{implicitly declared private here}}<br>
+// expected-note@-2 {{in instantiation of member function}}<br>
+<br>
+CMDIFrame wndMain;<br>
<br>
Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp<br>
------------------------------------------------------------------------------<br>
    svn:eol-style = native<br>
<br>
Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp<br>
------------------------------------------------------------------------------<br>
    svn:keywords = "Author Date Id Rev URL"<br>
<br>
Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp<br>
------------------------------------------------------------------------------<br>
    svn:mime-type = text/plain<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>