c++visual-studioc++20c++-modulesmsvc14

C++ "undefine" module keyword in include


I'd like to use C++20 modules in visual studio, but one of my projects uses Magick++ which defines a struct with a member char* named "module" in "magick++.h":

typedef struct _MagickInfo
{
  char
    *name,
    *description,
    *version,
    *mime_type,
    *note,
    *module; /* offending member here */

  /* ... other members ... */
} MagickInfo;

Can I tell the compiler to not process "module" in that specific #include?


Solution

  • module isn't a keyword (you can find the list of keywords in [lex.key] and verify that it isn't there).

    Instead, it's an "identifier with special meaning" ([lex.name]/2), more commonly referred to as a context-sensitive keyword.

    That is, there are only certain places where the module "keyword" is intended to be used, since module declarations can't appear everywhere. It's only those specific places that are going to be treated as module declarations. For a more thorough treatment of how the compiler might do this disambiguation, see P0924.

    One of the motivations for making module (and import) context-sensitive is that module is actually a fairly commonly used identifier in code - it's not just Magick++, there's also Vulkan.


    In short, the fact that you have a type with a member named module isn't going to cause problems. Having a type named module is worse (worse still if you have a global variable of that type - that could cause problems, but it would at least be possible to rewrite your code in such a way as to disambiguate the use of module in those situations).