diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -467,7 +467,6 @@ defvar hip = LangOpts<"HIP">; defvar gnu_mode = LangOpts<"GNUMode">; defvar asm_preprocessor = LangOpts<"AsmPreprocessor">; -defvar cpp_modules = LangOpts<"CPlusPlusModules">; defvar std = !strconcat("LangStandard::getLangStandardForKind(", lang_std.KeyPath, ")"); @@ -1332,8 +1331,11 @@ defm async_exceptions: BoolFOption<"async-exceptions", LangOpts<"EHAsynch">, DefaultFalse, PosFlag, NegFlag>; -def fcxx_modules : Flag <["-"], "fcxx-modules">, Group, - Flags<[NoXarchOption]>; +defm cxx_modules : BoolFOption<"cxx-modules", + LangOpts<"CPlusPlusModules">, Default, + NegFlag, PosFlag, + BothFlags<[NoXarchOption], " modules for C++">>, + ShouldParseIf; def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, Group; def fdebug_pass_structure : Flag<["-"], "fdebug-pass-structure">, Group; def fdepfile_entry : Joined<["-"], "fdepfile-entry=">, @@ -2154,7 +2156,7 @@ Flags<[CC1Option]>, HelpText<"Enable support for the C++ Modules TS">, MarshallingInfoFlag>; defm modules : BoolFOption<"modules", - LangOpts<"Modules">, Default, + LangOpts<"Modules">, Default, PosFlag, NegFlag, BothFlags<[NoXarchOption, CoreOption]>>; def fmodule_maps : Flag <["-"], "fmodule-maps">, Flags<[CoreOption]>, Alias; @@ -2213,8 +2215,6 @@ Flags<[CoreOption, NoXarchOption]>; def fno_common : Flag<["-"], "fno-common">, Group, Flags<[CC1Option]>, HelpText<"Compile common globals like normal definitions">; -def fno_cxx_modules : Flag <["-"], "fno-cxx-modules">, Group, - Flags<[NoXarchOption]>; defm digraphs : BoolFOption<"digraphs", LangOpts<"Digraphs">, Default, PosFlag', '<%', '%>', '%:', '%:%:' (default)">, @@ -5298,7 +5298,7 @@ HelpText<"Enforce name visibility rules across submodules of the same " "top-level module.">, MarshallingInfoFlag>, - ImpliedByAnyOf<[fmodules_ts.KeyPath, cpp_modules.KeyPath]>; + ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>; def fmodules_codegen : Flag<["-"], "fmodules-codegen">, HelpText<"Generate code for uses of this module that assumes an explicit " diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3150,8 +3150,6 @@ Opts.HexFloats = Std.hasHexFloats(); Opts.ImplicitInt = Std.hasImplicitInt(); - Opts.CPlusPlusModules = Opts.CPlusPlus20; - // Set OpenCL Version. Opts.OpenCL = Std.isOpenCL(); if (LangStd == LangStandard::lang_opencl10) diff --git a/clang/test/Modules/cxx20-disable.cpp b/clang/test/Modules/cxx20-disable.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Modules/cxx20-disable.cpp @@ -0,0 +1,10 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: %clang_cc1 -x objective-c++ -std=c++20 -I %t %s -verify=enabled +// RUN: %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s -verify=disabled + +// enabled-no-diagnostics + +// The spelling of these errors is misleading. +// The important thing is Clang rejected C++20 modules syntax. +export module Foo; // disabled-error{{expected template}} + // disabled-error@-1{{unknown type name 'module'}}