<div dir="ltr"><div dir="ltr">On Thu, 31 Oct 2019 at 01:45, Guofeng Zhang via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, <div><br></div><div>I just stat using clang 8 not long ago. I  need to compile our old c++ source without changing it. It is compiled with Visual Studio before. Now I want to migrate to clang as the compiler.</div><div><br></div><div>The following code segement can be compiled by clang:</div><div><br></div><div>1)  for (int i = 0 ; i < 6 ; i++ ) {</div><div>        ....</div><div>     }</div><div>     int k = i ;  // compiler error</div></div></blockquote><div><br></div><div>This code is relying on pre-standard C++ for loop scoping behavior (the code has been invalid for all 21 years of standard C++). Clang does not support this pre-standard behavior.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>2) unsigned short *s = ....</div><div>    wchar_t  *t = s ; // compiler error</div><div><br></div><div>I tried -ffor-scope and -fshort-wchar, but does not solve the issues.</div><div><br></div><div>are there clang compilation options to solve the issues?</div></div></blockquote><div><br></div><div>For the latter, something like "-Dwchar_t=unsigned short" might mostly work. (It won't support things like "wchar_t x = wchar_t(123);" though -- to support that you could put "typedef unsigned short my_wchar_t; #define wchar_t my_wchar_t" into a -include'd header.)</div><div><br></div><div>Generally. if you have the combination of ancient pre-standard C++ code that is invalid under any ISO C++ standard, and a requirement that you do not modify the code, you're going to have problems. Sorry. That said, Clang itself is open-source and modifiable, and it should be straightforward to add support for the above two constructs to Clang and build your own compiler that could perhaps accept this code. I'm not sure we'd want to accept patches for those non-standard behaviors upstream, though.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Thanks for your help very much,</div><div><br></div><div>Guofeng</div></div>
_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
</blockquote></div></div>