diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -109,6 +109,9 @@ "unable to open output file '%0': '%1'">; def warn_fe_macro_contains_embedded_newline : Warning< "macro '%0' contains embedded newline; text after the newline is ignored">; +def warn_fe_msvc_aligned_new_before_cpp17 : Warning< + "possible incompatibility with MSVC, it does not support alignedNew before C++17">, + InGroup; def warn_fe_cc_print_header_failure : Warning< "unable to open CC_PRINT_HEADERS file: %0 (using stderr)">; def warn_fe_cc_log_diagnostics_failure : Warning< diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -591,7 +591,8 @@ /// Initialize the predefined C++ language feature test macros defined in /// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations". static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, - MacroBuilder &Builder) { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) { // C++98 features. if (LangOpts.RTTI) Builder.defineMacro("__cpp_rtti", "199711L"); @@ -666,8 +667,13 @@ Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L"); Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L"); } - if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable) + if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable) { + // LLVM supports __cpp_aligned_new in C++ version older than C++17, but MSVC + // does not. Warn about the difference in support. + if (LangOpts.MSVCCompat && LangOpts.CPlusPlus && !LangOpts.CPlusPlus17) + Diags.Report(diag::warn_fe_msvc_aligned_new_before_cpp17); Builder.defineMacro("__cpp_aligned_new", "201606L"); + } if (LangOpts.RelaxedTemplateTemplateArgs) Builder.defineMacro("__cpp_template_template_args", "201611L"); @@ -728,7 +734,8 @@ const LangOptions &LangOpts, const FrontendOptions &FEOpts, const PreprocessorOptions &PPOpts, - MacroBuilder &Builder) { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) { // Compiler version introspection macros. Builder.defineMacro("__llvm__"); // LLVM Backend Builder.defineMacro("__clang__"); // Clang Frontend @@ -856,7 +863,7 @@ Twine(TI.useSignedCharForObjCBool() ? "0" : "1")); if (LangOpts.CPlusPlus) - InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder); + InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder, Diags); // darwin_constant_cfstrings controls this. This is also dependent // on other things like the runtime I believe. This is set even for C code. @@ -1326,10 +1333,10 @@ if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) && PP.getAuxTargetInfo()) InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, - PP.getPreprocessorOpts(), Builder); + PP.getPreprocessorOpts(), Builder, PP.getDiagnostics()); InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, - PP.getPreprocessorOpts(), Builder); + PP.getPreprocessorOpts(), Builder, PP.getDiagnostics()); // Install definitions to make Objective-C++ ARC work well with various // C++ Standard Library implementations.