[cfe-dev] Handling legacy VC++ deficiencies

Martin Vejnár Martin.Vejnar at avg.com
Tue Aug 28 08:21:12 PDT 2012


> Visual Studio 2005 generated a lot of code that uses unqualified pointers to
> member functions (think MFC dispatch tables; fear and loathing, sure, but
> the code is out there), and even 2012 supports them, although it now
> generates fully-qualified names ("&Class::Function", vs.
> accepting "Function" without "&" or "Class::"). I understand C++ requires a
> qualified name; on the other hand, I want to compile this corpus of legacy
> code with Clang (for analysis, not building).

I've tackled the same problem recently. It seems that MSVC10 is actually trying to remedy the problem and does not accept unqualified names for member functions in most contexts. AFAICT, the only context in which it allows it is an initializer list -- that's what ON_MESSAGE macros resolve to. Furthermore, these macros allow both unqualified and qualified names, so there's no straightforward way to fix the MFC headers.

I've hacked around the problem temporarily by adding __ensure_memptr keyword that turns the name into a qualified id and modified MFC headers accordingly (https://github.com/avakar/clang/commit/630050d3ca361770e2d5dd690ad084b87582468f). Naturaly, I'd rather have clang accept the unqualified id in MS mode directly, so +1 for the request.
 
> Another issue in such legacy code is expecting inheritance of typedefs in
> templates, whereas the standard requires redeclaring them explicitly (e.g.,
> types like value_type and pointer).

This is a problem with unqualified lookup in general. MSVC performs the lookup at instantiation time and looks into dependent base classes even though it shouldn't.
-- 
Martin





More information about the cfe-dev mailing list