From: Douglas Gregor Date: Wed, 18 Jan 2012 15:19:58 +0000 (+0000) Subject: In the driver, -fmodules enables modules for C/Objective-C but one X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64554ba9fc5f251108fd7d10a9c218e7bf985941;p=clang In the driver, -fmodules enables modules for C/Objective-C but one also needs -fcxx-modules to enable modules for C++/Objective-C++. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148393 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 4aaf1a0a4e..876fb577ef 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -296,6 +296,7 @@ def fconstexpr_backtrace_limit_EQ : Joined<"-fconstexpr-backtrace-limit=">, Group; def fcreate_profile : Flag<"-fcreate-profile">, Group; def fcxx_exceptions: Flag<"-fcxx-exceptions">, Group; +def fcxx_modules : Flag <"-fcxx-modules">, Group, Flags<[NoForward]>; def fdebug_pass_arguments : Flag<"-fdebug-pass-arguments">, Group; def fdebug_pass_structure : Flag<"-fdebug-pass-structure">, Group; def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group; @@ -401,6 +402,7 @@ def fno_color_diagnostics : Flag<"-fno-color-diagnostics">, Group; def fno_common : Flag<"-fno-common">, Group; def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">, Group; def fno_cxx_exceptions: Flag<"-fno-cxx-exceptions">, Group; +def fno_cxx_modules : Flag <"-fno-cxx-modules">, Group, Flags<[NoForward]>; def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, Group; def fno_diagnostics_show_name : Flag<"-fno-diagnostics-show-name">, Group; def fno_diagnostics_show_option : Flag<"-fno-diagnostics-show-option">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 39868c8236..9c50ae54ee 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2029,8 +2029,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fblocks-runtime-optional"); } - if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) - CmdArgs.push_back("-fmodules"); + // -fmodules enables modules (off by default). However, for C++/Objective-C++, + // users must also pass -fcxx-modules. The latter flag will disappear once the + // modules implementation is solid for C++/Objective-C++ programs as well. + if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) { + bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules, + options::OPT_fno_cxx_modules, + false); + if (AllowedInCXX || !types::isCXX(InputType)) + CmdArgs.push_back("-fmodules"); + } // -faccess-control is default. if (Args.hasFlag(options::OPT_fno_access_control, diff --git a/test/Driver/modules.mm b/test/Driver/modules.mm new file mode 100644 index 0000000000..b2948c4b3d --- /dev/null +++ b/test/Driver/modules.mm @@ -0,0 +1,6 @@ +// RUN: %clang -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s +// RUN: %clang -fcxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s +// CHECK-NO-MODULES-NOT: -fmodules + +// RUN: %clang -fcxx-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s +// CHECK-HAS-MODULES: -fmodules