diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index 6a7ceb7f70cb2..0b99545b6d58a 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -1105,7 +1105,10 @@ static bool LoadModule(const std::string &ModuleName, cling::Interpreter &interp cling::Interpreter::PushTransactionRAII RAII(&interp); if (clang::Module *M = moduleMap.findModule(ModuleName)) { clang::IdentifierInfo *II = PP.getIdentifierInfo(M->Name); - return !CI.getSema().ActOnModuleImport(ValidLoc, ValidLoc, std::make_pair(II, ValidLoc)).isInvalid(); + bool Result = !CI.getSema().ActOnModuleImport(ValidLoc, ValidLoc, std::make_pair(II, ValidLoc)).isInvalid(); + // Also make the module visible in the preprocessor to export its macros. + PP.makeModuleVisible(M, ValidLoc); + return Result; } return false; } @@ -1138,6 +1141,17 @@ static void LoadCoreModules(cling::Interpreter &interp) if (!LoadModule(moduleMap.findModule("RIO")->Name, interp)) Error("TCling::LoadCoreModules", "Cannot load module RIO"); + + // Check that the gROOT macro was exported by any core module. + assert(interp.getMacro("gROOT") && "Couldn't load gROOT macro?"); + + // C99 decided that it's a very good idea to name a macro `I` (the letter I). + // This seems to screw up nearly all the template code out there as `I` is + // common template parameter name and iterator variable name. + // Let's follow the GCC recommendation and undefine `I` in case any of the + // core modules have defined it: + // https://www.gnu.org/software/libc/manual/html_node/Complex-Numbers.html + interp.declare("#ifdef I\n #undef I\n #endif\n"); } static bool FileExists(const char *file)