diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 2b1319c1a0b5..a5f6789b7d1f 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -215,7 +215,7 @@ public: GNUInline = 0; NoInline = 0; - Deprecated = 1; // -Wdeprecated defaults to "on". + Deprecated = 0; CharIsSigned = 1; ShortWChar = 0; diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 716e27b90341..065fdd2c2c83 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -540,9 +540,9 @@ def fdelayed_template_parsing : Flag<"-fdelayed-template-parsing">, def funknown_anytype : Flag<"-funknown-anytype">, HelpText<"Enable parser support for the __unknown_anytype type; for testing purposes only">; def fdeprecated_macro : Flag<"-fdeprecated-macro">, - HelpText<"Defines the __DEPRECATED macro in C++ compilations">; + HelpText<"Defines the __DEPRECATED macro">; def fno_deprecated_macro : Flag<"-fno-deprecated-macro">, - HelpText<"Undefines the __DEPRECATED macro in C++ compilations">; + HelpText<"Undefines the __DEPRECATED macro">; //===----------------------------------------------------------------------===// // Header Search Options diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index f5dacfa6cfa2..2e74e272cb04 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1363,14 +1363,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } // GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active - // during C++ compilation. CC1 uses '-fdeprecated-macro' to control this. - // Both '-Wdeprecated' and '-fdeprecated-macro' default to on, so the flag - // logic here is inverted. - if (Args.hasFlag(options::OPT_Wno_deprecated, options::OPT_Wdeprecated, - false)) { - // GCC keeps this define even in the presence of '-w', match this behavior - // bug-for-bug. - CmdArgs.push_back("-fno-deprecated-macro"); + // during C++ compilation, which it is by default. GCC keeps this define even + // in the presence of '-w', match this behavior bug-for-bug. + if (types::isCXX(InputType) && + Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated, + true)) { + CmdArgs.push_back("-fdeprecated-macro"); } // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'. diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index daaaad0c2c6d..998ca8aa4ad4 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -694,8 +694,8 @@ static void LangOptsToArgs(const LangOptions &Opts, Res.push_back("-funknown-anytype"); if (Opts.DelayedTemplateParsing) Res.push_back("-fdelayed-template-parsing"); - if (!Opts.Deprecated) - Res.push_back("-fno-deprecated-macro"); + if (Opts.Deprecated) + Res.push_back("-fdeprecated-macro"); } static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts, diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 802d66ff0ea0..58379d3459fa 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -318,9 +318,10 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (LangOpts.SjLjExceptions) Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__"); + if (LangOpts.Deprecated) + Builder.defineMacro("__DEPRECATED"); + if (LangOpts.CPlusPlus) { - if (LangOpts.Deprecated) - Builder.defineMacro("__DEPRECATED"); Builder.defineMacro("__GNUG__", "4"); Builder.defineMacro("__GXX_WEAK__"); if (LangOpts.GNUMode) diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index 98952e60c1f3..4eed4aa06f3f 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -20,10 +20,12 @@ // RUN: %clang -### -S -Wwrite-strings -w %s 2>&1 | FileCheck -check-prefix=WRITE-STRINGS3 %s // WRITE-STRINGS3: -fconst-strings -// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s -// RUN: %clang -### -c -Wdeprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s -// RUN: %clang -### -c -Wno-deprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-OFF-CHECK %s -// RUN: %clang -### -c -Wno-deprecated -Wdeprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s -// RUN: %clang -### -c -w %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s -// DEPRECATED-OFF-CHECK: -fno-deprecated-macro -// DEPRECATED-ON-CHECK-NOT: -fno-deprecated-macro +// RUN: %clang -### -x c++ -c %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s +// RUN: %clang -### -x c++ -c -Wdeprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s +// RUN: %clang -### -x c++ -c -Wno-deprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-OFF-CHECK %s +// RUN: %clang -### -x c++ -c -Wno-deprecated -Wdeprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s +// RUN: %clang -### -x c++ -c -w %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s +// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=DEPRECATED-OFF-CHECK %s +// RUN: %clang -### -c -Wdeprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-OFF-CHECK %s +// DEPRECATED-ON-CHECK: -fdeprecated-macro +// DEPRECATED-OFF-CHECK-NOT: -fdeprecated-macro diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 606fecce70c0..a070f9a0b117 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -11,7 +11,6 @@ // // RUN: %clang_cc1 -x c++ -std=c++0x -E -dM < /dev/null | FileCheck -check-prefix CXX0X %s // -// CXX0X:#define __DEPRECATED 1 // CXX0X:#define __GNUG__ // CXX0X:#define __GXX_EXPERIMENTAL_CXX0X__ 1 // CXX0X:#define __GXX_RTTI 1 @@ -22,7 +21,6 @@ // // RUN: %clang_cc1 -x c++ -std=c++98 -E -dM < /dev/null | FileCheck -check-prefix CXX98 %s // -// CXX98:#define __DEPRECATED 1 // CXX98:#define __GNUG__ // CXX98:#define __GXX_RTTI 1 // CXX98:#define __GXX_WEAK__ 1 @@ -30,6 +28,11 @@ // CXX98:#define __private_extern__ extern // // +// RUN: %clang_cc1 -fdeprecated-macro -E -dM < /dev/null | FileCheck -check-prefix DEPRECATED %s +// +// DEPRECATED:#define __DEPRECATED 1 +// +// // RUN: %clang_cc1 -std=c99 -E -dM < /dev/null | FileCheck -check-prefix C99 %s // // C99:#define __STDC_VERSION__ 199901L @@ -62,7 +65,6 @@ // // RUN: %clang_cc1 -x c++ -std=gnu++98 -E -dM < /dev/null | FileCheck -check-prefix GXX98 %s // -// GXX98:#define __DEPRECATED 1 // GXX98:#define __GNUG__ // GXX98:#define __GXX_WEAK__ 1 // GXX98:#define __cplusplus 1