@@ -3724,20 +3724,10 @@ bool Driver::getDefaultModuleCachePath(SmallVectorImpl<char> &Result) {
3724
3724
3725
3725
static bool RenderModulesOptions (Compilation &C, const Driver &D,
3726
3726
const ArgList &Args, const InputInfo &Input,
3727
- const InputInfo &Output, const Arg *Std ,
3727
+ const InputInfo &Output, bool HaveStd20 ,
3728
3728
ArgStringList &CmdArgs) {
3729
3729
bool IsCXX = types::isCXX (Input.getType ());
3730
- // FIXME: Find a better way to determine whether the input has standard c++
3731
- // modules support by default.
3732
- bool HaveStdCXXModules =
3733
- IsCXX && Std &&
3734
- (Std->containsValue (" c++2a" ) || Std->containsValue (" gnu++2a" ) ||
3735
- Std->containsValue (" c++20" ) || Std->containsValue (" gnu++20" ) ||
3736
- Std->containsValue (" c++2b" ) || Std->containsValue (" gnu++2b" ) ||
3737
- Std->containsValue (" c++23" ) || Std->containsValue (" gnu++23" ) ||
3738
- Std->containsValue (" c++2c" ) || Std->containsValue (" gnu++2c" ) ||
3739
- Std->containsValue (" c++26" ) || Std->containsValue (" gnu++26" ) ||
3740
- Std->containsValue (" c++latest" ) || Std->containsValue (" gnu++latest" ));
3730
+ bool HaveStdCXXModules = IsCXX && HaveStd20;
3741
3731
bool HaveModules = HaveStdCXXModules;
3742
3732
3743
3733
// -fmodules enables the use of precompiled modules (off by default).
@@ -6842,14 +6832,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
6842
6832
(!IsWindowsMSVC || IsMSVC2015Compatible)))
6843
6833
CmdArgs.push_back (" -fno-threadsafe-statics" );
6844
6834
6845
- // -fno-delayed-template-parsing is default, except when targeting MSVC.
6846
- // Many old Windows SDK versions require this to parse.
6847
- // FIXME: MSVC introduced /Zc:twoPhase- to disable this behavior in their
6848
- // compiler. We should be able to disable this by default at some point.
6849
- if (Args.hasFlag (options::OPT_fdelayed_template_parsing,
6850
- options::OPT_fno_delayed_template_parsing, IsWindowsMSVC))
6851
- CmdArgs.push_back (" -fdelayed-template-parsing" );
6852
-
6853
6835
// -fgnu-keywords default varies depending on language; only pass if
6854
6836
// specified.
6855
6837
Args.AddLastArg (CmdArgs, options::OPT_fgnu_keywords,
@@ -6870,8 +6852,38 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
6870
6852
6871
6853
Args.AddLastArg (CmdArgs, options::OPT_finline_max_stacksize_EQ);
6872
6854
6855
+ // FIXME: Find a better way to determine whether we are in C++20.
6856
+ bool HaveCxx20 =
6857
+ Std &&
6858
+ (Std->containsValue (" c++2a" ) || Std->containsValue (" gnu++2a" ) ||
6859
+ Std->containsValue (" c++20" ) || Std->containsValue (" gnu++20" ) ||
6860
+ Std->containsValue (" c++2b" ) || Std->containsValue (" gnu++2b" ) ||
6861
+ Std->containsValue (" c++23" ) || Std->containsValue (" gnu++23" ) ||
6862
+ Std->containsValue (" c++2c" ) || Std->containsValue (" gnu++2c" ) ||
6863
+ Std->containsValue (" c++26" ) || Std->containsValue (" gnu++26" ) ||
6864
+ Std->containsValue (" c++latest" ) || Std->containsValue (" gnu++latest" ));
6873
6865
bool HaveModules =
6874
- RenderModulesOptions (C, D, Args, Input, Output, Std, CmdArgs);
6866
+ RenderModulesOptions (C, D, Args, Input, Output, HaveCxx20, CmdArgs);
6867
+
6868
+ // -fdelayed-template-parsing is default when targeting MSVC.
6869
+ // Many old Windows SDK versions require this to parse.
6870
+ //
6871
+ // According to
6872
+ // https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-170,
6873
+ // MSVC actually defaults to -fno-delayed-template-parsing (/Zc:twoPhase-
6874
+ // with MSVC CLI) if using C++20. So we match the behavior with MSVC here to
6875
+ // not enable -fdelayed-template-parsing by default after C++20.
6876
+ //
6877
+ // FIXME: Given -fdelayed-template-parsing is a source of bugs, we should be
6878
+ // able to disable this by default at some point.
6879
+ if (Args.hasFlag (options::OPT_fdelayed_template_parsing,
6880
+ options::OPT_fno_delayed_template_parsing,
6881
+ IsWindowsMSVC && !HaveCxx20)) {
6882
+ if (HaveCxx20)
6883
+ D.Diag (clang::diag::warn_drv_delayed_template_parsing_after_cxx20);
6884
+
6885
+ CmdArgs.push_back (" -fdelayed-template-parsing" );
6886
+ }
6875
6887
6876
6888
if (Args.hasFlag (options::OPT_fpch_validate_input_files_content,
6877
6889
options::OPT_fno_pch_validate_input_files_content, false ))
0 commit comments