Revert "[Clang] [NFC] Introduce a helper for emitting compatibility diagnostics" (#134036)
Reverts llvm/llvm-project#132348
Some tests are failing and I still need to figure out what is going on
here.
diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt
index 6be6d06..a671d5c 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -8,11 +8,6 @@
-gen-clang-diags-enums -clang-component=${component}
SOURCE Diagnostic.td
TARGET ClangDiagnostic${component}Enums)
-
- clang_tablegen(Diagnostic${component}CompatIDs.inc
- -gen-clang-diags-compat-ids -clang-component=${component}
- SOURCE Diagnostic.td
- TARGET ClangDiagnostic${component}CompatIDs)
endmacro(clang_diag_gen)
clang_diag_gen(Analysis)
@@ -36,11 +31,6 @@
SOURCE Diagnostic.td
TARGET ClangDiagnosticIndexName)
-clang_tablegen(DiagnosticAllCompatIDs.inc
- -gen-clang-diags-compat-ids
- SOURCE Diagnostic.td
- TARGET ClangDiagnosticAllCompatIDs)
-
clang_tablegen(AttrList.inc -gen-clang-attr-list
-I ${CMAKE_CURRENT_SOURCE_DIR}/../../
SOURCE Attr.td
diff --git a/clang/include/clang/Basic/Diagnostic.td b/clang/include/clang/Basic/Diagnostic.td
index 65b19f3..b31d846 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -155,19 +155,6 @@
}
class DefaultRemark { Severity DefaultSeverity = SEV_Remark; }
-class CompatWarningId<string name, int std, string diag, string diag_pre> {
- string Component = ?;
- string Name = name;
- string Diag = diag;
- string DiagPre = diag_pre;
- int Std = std;
-
- // This is unused, but Tablegen will complain if it's missing because we define
- // the compatibility ids in the same place as the other diagnostics (which means
- // that we'll be inside a 'let CategoryName = "" in { ... }' block).
- string CategoryName = ?;
-}
-
// C++ compatibility warnings.
multiclass CXXCompat<
string message,
@@ -191,11 +178,6 @@
"CXX98Compat",
"CXXPre"#std_ver#"Compat"))>,
DefaultIgnore;
-
- def : CompatWarningId<
- NAME, std_ver,
- "compat_cxx"#std_ver#"_"#NAME,
- "compat_pre_cxx"#std_ver#"_"#NAME>;
}
// These generate pairs of C++ compatibility warnings of the form:
diff --git a/clang/include/clang/Basic/DiagnosticAST.h b/clang/include/clang/Basic/DiagnosticAST.h
index 41e2598..4f82114 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticASTCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICAST_H
diff --git a/clang/include/clang/Basic/DiagnosticAnalysis.h b/clang/include/clang/Basic/DiagnosticAnalysis.h
index 5ead092..1a49461 100644
--- a/clang/include/clang/Basic/DiagnosticAnalysis.h
+++ b/clang/include/clang/Basic/DiagnosticAnalysis.h
@@ -35,18 +35,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticAnalysisCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICANALYSIS_H
diff --git a/clang/include/clang/Basic/DiagnosticComment.h b/clang/include/clang/Basic/DiagnosticComment.h
index 08e66e8..53143ef 100644
--- a/clang/include/clang/Basic/DiagnosticComment.h
+++ b/clang/include/clang/Basic/DiagnosticComment.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticCommentCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICCOMMENT_H
diff --git a/clang/include/clang/Basic/DiagnosticCrossTU.h b/clang/include/clang/Basic/DiagnosticCrossTU.h
index 761716d..428da95 100644
--- a/clang/include/clang/Basic/DiagnosticCrossTU.h
+++ b/clang/include/clang/Basic/DiagnosticCrossTU.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticCrossTUCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICCROSSTU_H
diff --git a/clang/include/clang/Basic/DiagnosticDriver.h b/clang/include/clang/Basic/DiagnosticDriver.h
index 864a23a..c472afa 100644
--- a/clang/include/clang/Basic/DiagnosticDriver.h
+++ b/clang/include/clang/Basic/DiagnosticDriver.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticDriverCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICDRIVER_H
diff --git a/clang/include/clang/Basic/DiagnosticFrontend.h b/clang/include/clang/Basic/DiagnosticFrontend.h
index 3506f05..766cac3 100644
--- a/clang/include/clang/Basic/DiagnosticFrontend.h
+++ b/clang/include/clang/Basic/DiagnosticFrontend.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticFrontendCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICFRONTEND_H
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h b/clang/include/clang/Basic/DiagnosticIDs.h
index f2bd19f..017ef706 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -25,7 +25,6 @@
namespace clang {
class DiagnosticsEngine;
class DiagnosticBuilder;
- class LangOptions;
class SourceLocation;
// Import the diagnostic enums themselves.
@@ -105,18 +104,6 @@
};
}
- namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticCommonCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
- } // end namespace diag_compat
-
class DiagnosticMapping {
LLVM_PREFERRED_TYPE(diag::Severity)
unsigned Severity : 3;
@@ -477,11 +464,6 @@
/// given group name.
static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group);
- /// Get the appropriate diagnostic Id to use for issuing a compatibility
- /// diagnostic. For use by the various DiagCompat() helpers.
- static unsigned getCXXCompatDiagId(const LangOptions &LangOpts,
- unsigned CompatDiagId);
-
private:
/// Classify the specified diagnostic ID into a Level, consumable by
/// the DiagnosticClient.
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h b/clang/include/clang/Basic/DiagnosticInstallAPI.h
index 4619bfe..cbdb003 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPI.h
+++ b/clang/include/clang/Basic/DiagnosticInstallAPI.h
@@ -35,17 +35,5 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticInstallAPICompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
diff --git a/clang/include/clang/Basic/DiagnosticLex.h b/clang/include/clang/Basic/DiagnosticLex.h
index 6fa90f7..d14bf97 100644
--- a/clang/include/clang/Basic/DiagnosticLex.h
+++ b/clang/include/clang/Basic/DiagnosticLex.h
@@ -35,18 +35,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticLexCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICLEX_H
diff --git a/clang/include/clang/Basic/DiagnosticParse.h b/clang/include/clang/Basic/DiagnosticParse.h
index e2a4368a..275e1a4 100644
--- a/clang/include/clang/Basic/DiagnosticParse.h
+++ b/clang/include/clang/Basic/DiagnosticParse.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticParseCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICPARSE_H
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 954f538..2582e1e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -11,12 +11,6 @@
//===----------------------------------------------------------------------===//
let Component = "Parse" in {
-let CategoryName = "Parse Issue" in {
-// C++11 compatibility with C++98.
-defm enum_fixed_underlying_type : CXX11Compat<
- "enumeration types with a fixed underlying type are",
- /*ext_warn=*/false>;
-}
def err_asm_qualifier_ignored : Error<
"expected 'volatile', 'inline', 'goto', or '('">, CatInlineAsm;
@@ -113,6 +107,9 @@
"missing ',' between enumerators">;
def err_enumerator_unnamed_no_def : Error<
"unnamed enumeration must be a definition">;
+def ext_cxx11_enum_fixed_underlying_type : Extension<
+ "enumeration types with a fixed underlying type are a C++11 extension">,
+ InGroup<CXX11>;
def ext_ms_c_enum_fixed_underlying_type : Extension<
"enumeration types with a fixed underlying type are a Microsoft extension">,
InGroup<MicrosoftFixedEnum>;
@@ -122,6 +119,9 @@
def warn_c17_compat_enum_fixed_underlying_type : Warning<
"enumeration types with a fixed underlying type are incompatible with C standards before C23">,
DefaultIgnore, InGroup<CPre23Compat>;
+def warn_cxx98_compat_enum_fixed_underlying_type : Warning<
+ "enumeration types with a fixed underlying type are incompatible with C++98">,
+ InGroup<CXX98Compat>, DefaultIgnore;
def ext_enum_base_in_type_specifier : ExtWarn<
"non-defining declaration of enumeration with a fixed underlying type is "
"only permitted as a standalone declaration"
diff --git a/clang/include/clang/Basic/DiagnosticRefactoring.h b/clang/include/clang/Basic/DiagnosticRefactoring.h
index b3f3a10..59d4bc9 100644
--- a/clang/include/clang/Basic/DiagnosticRefactoring.h
+++ b/clang/include/clang/Basic/DiagnosticRefactoring.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticRefactoringCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICREFACTORING_H
diff --git a/clang/include/clang/Basic/DiagnosticSema.h b/clang/include/clang/Basic/DiagnosticSema.h
index 943b2f64..84986c7 100644
--- a/clang/include/clang/Basic/DiagnosticSema.h
+++ b/clang/include/clang/Basic/DiagnosticSema.h
@@ -35,20 +35,7 @@
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
-
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticSemaCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICSEMA_H
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 265bed2..5e45482 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -61,7 +61,7 @@
// Compatibility warnings duplicated across multiple language versions.
foreach std = [14, 20, 23] in {
- defm cxx#std#_constexpr_body_invalid_stmt : CXXCompat<
+ defm constexpr_body_invalid_stmt : CXXCompat<
"use of this statement in a constexpr %select{function|constructor}0 is", std>;
}
diff --git a/clang/include/clang/Basic/DiagnosticSerialization.h b/clang/include/clang/Basic/DiagnosticSerialization.h
index c8fb034..6fb836d 100644
--- a/clang/include/clang/Basic/DiagnosticSerialization.h
+++ b/clang/include/clang/Basic/DiagnosticSerialization.h
@@ -36,18 +36,6 @@
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END() \
- } \
- ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticSerializationCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
} // end namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICSERIALIZATION_H
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 5770692..c8ceef8 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1263,12 +1263,6 @@
return Diag(Tok, DiagID);
}
- DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId);
- DiagnosticBuilder DiagCompat(const Token &Tok, unsigned CompatDiagId);
- DiagnosticBuilder DiagCompat(unsigned CompatDiagId) {
- return DiagCompat(Tok, CompatDiagId);
- }
-
private:
void SuggestParentheses(SourceLocation Loc, unsigned DK,
SourceRange ParenRange);
diff --git a/clang/include/clang/Sema/SemaBase.h b/clang/include/clang/Sema/SemaBase.h
index 550f530..463cae8 100644
--- a/clang/include/clang/Sema/SemaBase.h
+++ b/clang/include/clang/Sema/SemaBase.h
@@ -219,10 +219,6 @@
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
bool DeferHint = false);
- /// Emit a compatibility diagnostic.
- SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId,
- bool DeferHint = false);
-
/// Build a partial diagnostic.
PartialDiagnostic PDiag(unsigned DiagID = 0);
};
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index d592843..ca5b8d2 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -13,7 +13,6 @@
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/AllDiagnostics.h"
#include "clang/Basic/DiagnosticCategories.h"
-#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
@@ -770,51 +769,6 @@
return Best;
}
-unsigned DiagnosticIDs::getCXXCompatDiagId(const LangOptions &LangOpts,
- unsigned CompatDiagId) {
- struct CompatDiag {
- unsigned StdVer;
- unsigned DiagId;
- unsigned PreDiagId;
- };
-
- // We encode the standard version such that C++98 < C++11 < C++14 etc. The
- // actual numbers don't really matter for this, but the definitions of the
- // compat diags in the Tablegen file use the standard version number (i.e.
- // 98, 11, 14, etc.), so we base the encoding here on that.
-#define DIAG_COMPAT_IDS_BEGIN()
-#define DIAG_COMPAT_IDS_END()
-#define DIAG_COMPAT_ID(Value, Name, Std, Diag, DiagPre) \
- {Std == 98 ? 1998 : 2000 + Std, diag::Diag, diag::DiagPre},
- static constexpr CompatDiag Diags[]{
-#include "clang/Basic/DiagnosticAllCompatIDs.inc"
- };
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-
- assert(CompatDiagId < std::size(Diags) && "Invalid compat diag id");
-
- unsigned StdVer = [&] {
- if (LangOpts.CPlusPlus26)
- return 2026;
- if (LangOpts.CPlusPlus23)
- return 2023;
- if (LangOpts.CPlusPlus20)
- return 2020;
- if (LangOpts.CPlusPlus17)
- return 2017;
- if (LangOpts.CPlusPlus14)
- return 2014;
- if (LangOpts.CPlusPlus11)
- return 2011;
- return 1998;
- }();
-
- const CompatDiag &D = Diags[CompatDiagId];
- return StdVer >= D.StdVer ? D.DiagId : D.PreDiagId;
-}
-
/// ProcessDiag - This is the method used to report a diagnostic that is
/// finally fully formed.
bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag,
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index d77400e..3f15640 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -5452,8 +5452,11 @@
BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
if (!getLangOpts().ObjC) {
- if (getLangOpts().CPlusPlus)
- DiagCompat(ColonLoc, diag_compat::enum_fixed_underlying_type)
+ if (getLangOpts().CPlusPlus11)
+ Diag(ColonLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type)
+ << BaseRange;
+ else if (getLangOpts().CPlusPlus)
+ Diag(ColonLoc, diag::ext_cxx11_enum_fixed_underlying_type)
<< BaseRange;
else if (getLangOpts().MicrosoftExt && !getLangOpts().C23)
Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 1227514..2eca891 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -89,16 +89,6 @@
return Diag(Tok.getLocation(), DiagID);
}
-DiagnosticBuilder Parser::DiagCompat(SourceLocation Loc,
- unsigned CompatDiagId) {
- return Diag(Loc,
- DiagnosticIDs::getCXXCompatDiagId(getLangOpts(), CompatDiagId));
-}
-
-DiagnosticBuilder Parser::DiagCompat(const Token &Tok, unsigned CompatDiagId) {
- return DiagCompat(Tok.getLocation(), CompatDiagId);
-}
-
/// Emits a diagnostic suggesting parentheses surrounding a
/// given range.
///
diff --git a/clang/lib/Sema/SemaBase.cpp b/clang/lib/Sema/SemaBase.cpp
index 9b677f4..85c4a0a 100644
--- a/clang/lib/Sema/SemaBase.cpp
+++ b/clang/lib/Sema/SemaBase.cpp
@@ -88,11 +88,4 @@
return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
}
-SemaBase::SemaDiagnosticBuilder SemaBase::DiagCompat(SourceLocation Loc,
- unsigned CompatDiagId,
- bool DeferHint) {
- return Diag(Loc,
- DiagnosticIDs::getCXXCompatDiagId(getLangOpts(), CompatDiagId),
- DeferHint);
-}
} // namespace clang
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9b7b3f8..bbefbbf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7649,7 +7649,10 @@
IsVariableTemplate = true;
// Only C++1y supports variable templates (N3651).
- DiagCompat(D.getIdentifierLoc(), diag_compat::variable_template);
+ Diag(D.getIdentifierLoc(),
+ getLangOpts().CPlusPlus14
+ ? diag::compat_cxx14_variable_template
+ : diag::compat_pre_cxx14_variable_template);
}
}
} else {
@@ -7715,8 +7718,10 @@
} else if (RD->isUnion()) {
// C++98 [class.union]p1: If a union contains a static data member,
// the program is ill-formed. C++11 drops this restriction.
- DiagCompat(D.getIdentifierLoc(),
- diag_compat::static_data_member_in_union)
+ Diag(D.getIdentifierLoc(),
+ getLangOpts().CPlusPlus11
+ ? diag::compat_cxx11_static_data_member_in_union
+ : diag::compat_pre_cxx11_static_data_member_in_union)
<< Name;
}
}
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b6ba723..43bf9b7c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -807,8 +807,10 @@
for (auto Loc : BadSpecifierLocs)
Err << SourceRange(Loc, Loc);
} else if (!CPlusPlus20Specifiers.empty()) {
- auto &&Warn = DiagCompat(CPlusPlus20SpecifierLocs.front(),
- diag_compat::decomp_decl_spec);
+ auto &&Warn = Diag(CPlusPlus20SpecifierLocs.front(),
+ getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_decomp_decl_spec
+ : diag::compat_pre_cxx20_decomp_decl_spec);
Warn << (int)CPlusPlus20Specifiers.size()
<< llvm::join(CPlusPlus20Specifiers.begin(),
CPlusPlus20Specifiers.end(), " ");
@@ -2038,8 +2040,10 @@
// C++1y allows types to be defined, not just declared.
if (cast<TagDecl>(DclIt)->isThisDeclarationADefinition()) {
if (Kind == Sema::CheckConstexprKind::Diagnose) {
- SemaRef.DiagCompat(DS->getBeginLoc(),
- diag_compat::constexpr_type_definition)
+ SemaRef.Diag(DS->getBeginLoc(),
+ SemaRef.getLangOpts().CPlusPlus14
+ ? diag::compat_cxx14_constexpr_type_definition
+ : diag::compat_pre_cxx14_constexpr_type_definition)
<< isa<CXXConstructorDecl>(Dcl);
} else if (!SemaRef.getLangOpts().CPlusPlus14) {
return false;
@@ -2064,8 +2068,10 @@
if (VD->isThisDeclarationADefinition()) {
if (VD->isStaticLocal()) {
if (Kind == Sema::CheckConstexprKind::Diagnose) {
- SemaRef.DiagCompat(VD->getLocation(),
- diag_compat::constexpr_static_var)
+ SemaRef.Diag(VD->getLocation(),
+ SemaRef.getLangOpts().CPlusPlus23
+ ? diag::compat_cxx23_constexpr_static_var
+ : diag::compat_pre_cxx23_constexpr_static_var)
<< isa<CXXConstructorDecl>(Dcl)
<< (VD->getTLSKind() == VarDecl::TLS_Dynamic);
} else if (!SemaRef.getLangOpts().CPlusPlus23) {
@@ -2085,8 +2091,11 @@
if (!VD->getType()->isDependentType() &&
!VD->hasInit() && !VD->isCXXForRangeDecl()) {
if (Kind == Sema::CheckConstexprKind::Diagnose) {
- SemaRef.DiagCompat(VD->getLocation(),
- diag_compat::constexpr_local_var_no_init)
+ SemaRef.Diag(
+ VD->getLocation(),
+ SemaRef.getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_constexpr_local_var_no_init
+ : diag::compat_pre_cxx20_constexpr_local_var_no_init)
<< isa<CXXConstructorDecl>(Dcl);
} else if (!SemaRef.getLangOpts().CPlusPlus20) {
return false;
@@ -2095,7 +2104,10 @@
}
}
if (Kind == Sema::CheckConstexprKind::Diagnose) {
- SemaRef.DiagCompat(VD->getLocation(), diag_compat::constexpr_local_var)
+ SemaRef.Diag(VD->getLocation(),
+ SemaRef.getLangOpts().CPlusPlus14
+ ? diag::compat_cxx14_constexpr_local_var
+ : diag::compat_pre_cxx14_constexpr_local_var)
<< isa<CXXConstructorDecl>(Dcl);
} else if (!SemaRef.getLangOpts().CPlusPlus14) {
return false;
@@ -2165,8 +2177,10 @@
if (!Inits.count(Field)) {
if (Kind == Sema::CheckConstexprKind::Diagnose) {
if (!Diagnosed) {
- SemaRef.DiagCompat(Dcl->getLocation(),
- diag_compat::constexpr_ctor_missing_init);
+ SemaRef.Diag(Dcl->getLocation(),
+ SemaRef.getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_constexpr_ctor_missing_init
+ : diag::compat_pre_cxx20_constexpr_ctor_missing_init);
Diagnosed = true;
}
SemaRef.Diag(Field->getLocation(),
@@ -2377,8 +2391,10 @@
break;
case Sema::CheckConstexprKind::Diagnose:
- SemaRef.DiagCompat(Body->getBeginLoc(),
- diag_compat::constexpr_function_try_block)
+ SemaRef.Diag(Body->getBeginLoc(),
+ SemaRef.getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_constexpr_function_try_block
+ : diag::compat_pre_cxx20_constexpr_function_try_block)
<< isa<CXXConstructorDecl>(Dcl);
break;
}
@@ -2405,13 +2421,22 @@
(Cxx1yLoc.isValid() && !SemaRef.getLangOpts().CPlusPlus17))
return false;
} else if (Cxx2bLoc.isValid()) {
- SemaRef.DiagCompat(Cxx2bLoc, diag_compat::cxx23_constexpr_body_invalid_stmt)
+ SemaRef.Diag(Cxx2bLoc,
+ SemaRef.getLangOpts().CPlusPlus23
+ ? diag::compat_cxx23_constexpr_body_invalid_stmt
+ : diag::compat_pre_cxx23_constexpr_body_invalid_stmt)
<< isa<CXXConstructorDecl>(Dcl);
} else if (Cxx2aLoc.isValid()) {
- SemaRef.DiagCompat(Cxx2aLoc, diag_compat::cxx20_constexpr_body_invalid_stmt)
+ SemaRef.Diag(Cxx2aLoc,
+ SemaRef.getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_constexpr_body_invalid_stmt
+ : diag::compat_pre_cxx20_constexpr_body_invalid_stmt)
<< isa<CXXConstructorDecl>(Dcl);
} else if (Cxx1yLoc.isValid()) {
- SemaRef.DiagCompat(Cxx1yLoc, diag_compat::cxx14_constexpr_body_invalid_stmt)
+ SemaRef.Diag(Cxx1yLoc,
+ SemaRef.getLangOpts().CPlusPlus14
+ ? diag::compat_cxx14_constexpr_body_invalid_stmt
+ : diag::compat_pre_cxx14_constexpr_body_invalid_stmt)
<< isa<CXXConstructorDecl>(Dcl);
}
@@ -2428,8 +2453,11 @@
if (Constructor->getNumCtorInitializers() == 0 &&
RD->hasVariantMembers()) {
if (Kind == Sema::CheckConstexprKind::Diagnose) {
- SemaRef.DiagCompat(Dcl->getLocation(),
- diag_compat::constexpr_union_ctor_no_init);
+ SemaRef.Diag(
+ Dcl->getLocation(),
+ SemaRef.getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_constexpr_union_ctor_no_init
+ : diag::compat_pre_cxx20_constexpr_union_ctor_no_init);
} else if (!SemaRef.getLangOpts().CPlusPlus20) {
return false;
}
@@ -2492,8 +2520,11 @@
} else if (ReturnStmts.size() > 1) {
switch (Kind) {
case Sema::CheckConstexprKind::Diagnose:
- SemaRef.DiagCompat(ReturnStmts.back(),
- diag_compat::constexpr_body_multiple_return);
+ SemaRef.Diag(
+ ReturnStmts.back(),
+ SemaRef.getLangOpts().CPlusPlus14
+ ? diag::compat_cxx14_constexpr_body_multiple_return
+ : diag::compat_pre_cxx14_constexpr_body_multiple_return);
for (unsigned I = 0; I < ReturnStmts.size() - 1; ++I)
SemaRef.Diag(ReturnStmts[I],
diag::note_constexpr_body_previous_return);
@@ -17794,7 +17825,9 @@
<< FixItHint::CreateInsertion(getLocForEndOfToken(FriendLoc),
InsertionText);
} else {
- DiagCompat(FriendLoc, diag_compat::nonclass_type_friend)
+ Diag(FriendLoc, getLangOpts().CPlusPlus11
+ ? diag::compat_cxx11_nonclass_type_friend
+ : diag::compat_pre_cxx11_nonclass_type_friend)
<< T << DS.getSourceRange();
}
}
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e7f418a..7cc8374 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6508,7 +6508,9 @@
if (const auto *ULE = dyn_cast<UnresolvedLookupExpr>(Fn);
ULE && ULE->hasExplicitTemplateArgs() &&
ULE->decls_begin() == ULE->decls_end()) {
- DiagCompat(Fn->getExprLoc(), diag_compat::adl_only_template_id)
+ Diag(Fn->getExprLoc(), getLangOpts().CPlusPlus20
+ ? diag::compat_cxx20_adl_only_template_id
+ : diag::compat_pre_cxx20_adl_only_template_id)
<< ULE->getName();
}
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 1f87ef4..eace9b87 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2234,7 +2234,10 @@
// template-argument, that declaration shall be a definition and shall be
// the only declaration of the function template in the translation unit.
// (C++98/03 doesn't have this wording; see DR226).
- S.DiagCompat(ParamLoc, diag_compat::templ_default_in_function_templ)
+ S.Diag(ParamLoc,
+ S.getLangOpts().CPlusPlus11
+ ? diag::compat_cxx11_templ_default_in_function_templ
+ : diag::compat_pre_cxx11_templ_default_in_function_templ)
<< DefArgRange;
return false;
@@ -6429,7 +6432,10 @@
bool ExtraParens = false;
while (ParenExpr *Parens = dyn_cast<ParenExpr>(Arg)) {
if (!Invalid && !ExtraParens) {
- S.DiagCompat(Arg->getBeginLoc(), diag_compat::template_arg_extra_parens)
+ S.Diag(Arg->getBeginLoc(),
+ S.getLangOpts().CPlusPlus11
+ ? diag::compat_cxx11_template_arg_extra_parens
+ : diag::compat_pre_cxx11_template_arg_extra_parens)
<< Arg->getSourceRange();
ExtraParens = true;
}
@@ -6649,7 +6655,10 @@
bool ExtraParens = false;
while (ParenExpr *Parens = dyn_cast<ParenExpr>(Arg)) {
if (!Invalid && !ExtraParens) {
- S.DiagCompat(Arg->getBeginLoc(), diag_compat::template_arg_extra_parens)
+ S.Diag(Arg->getBeginLoc(),
+ S.getLangOpts().CPlusPlus11
+ ? diag::compat_cxx11_template_arg_extra_parens
+ : diag::compat_pre_cxx11_template_arg_extra_parens)
<< Arg->getSourceRange();
ExtraParens = true;
}
@@ -10630,7 +10639,9 @@
return true;
if (TypenameLoc.isValid() && S && !S->getTemplateParamParent())
- DiagCompat(TypenameLoc, diag_compat::typename_outside_of_template)
+ Diag(TypenameLoc, getLangOpts().CPlusPlus11
+ ? diag::compat_cxx11_typename_outside_of_template
+ : diag::compat_pre_cxx11_typename_outside_of_template)
<< FixItHint::CreateRemoval(TypenameLoc);
NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);
diff --git a/clang/test/Misc/show-diag-options.c b/clang/test/Misc/show-diag-options.c
index b098203..4e98d63 100644
--- a/clang/test/Misc/show-diag-options.c
+++ b/clang/test/Misc/show-diag-options.c
@@ -18,7 +18,7 @@
// BASE: {{.*}}: warning: {{[a-z ]+$}}
// OPTION: {{.*}}: warning: {{[a-z ]+}} [-Wparentheses]
// OPTION_ERROR: {{.*}}: error: {{[a-z ]+}} [-Werror,-Wparentheses]
- // CATEGORY_ID: {{.*}}: warning: {{[a-z ]+}} [{{[0-9]+}}]
+ // CATEGORY_ID: {{.*}}: warning: {{[a-z ]+}} [2]
// CATEGORY_NAME: {{.*}}: warning: {{[a-z ]+}} [Semantic Issue]
// OPTION_ERROR_CATEGORY: {{.*}}: error: {{[a-z ]+}} [-Werror,-Wparentheses,Semantic Issue]
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 73facbc..8f846a4 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1518,50 +1518,6 @@
// runs into odd situations like [[clang::warn_unused_result]],
// #pragma clang, or --unwindlib=libgcc.
}
-
-/// ClangDiagsCompatIDsEmitter - Emit a set of 'compatibility diagnostic ids'
-/// that map to a set of 2 regular diagnostic ids each and which are used to
-/// simplify emitting compatibility warnings.
-void clang::EmitClangDiagsCompatIDs(const llvm::RecordKeeper &Records,
- llvm::raw_ostream &OS,
- const std::string &Component) {
- ArrayRef<const Record *> Ids =
- Records.getAllDerivedDefinitions("CompatWarningId");
-
- StringRef PrevComponent = "";
- for (auto [I, R] : enumerate(make_pointee_range(Ids))) {
- StringRef DiagComponent = R.getValueAsString("Component");
- if (!Component.empty() && Component != DiagComponent)
- continue;
-
- StringRef CompatDiagName = R.getValueAsString("Name");
- StringRef Diag = R.getValueAsString("Diag");
- StringRef DiagPre = R.getValueAsString("DiagPre");
- int64_t CXXStdVer = R.getValueAsInt("Std");
-
- // We don't want to create empty enums since some compilers (including
- // Clang) warn about that, so these macros are used to avoid having to
- // unconditionally write 'enum {' and '};' in the headers.
- if (PrevComponent != DiagComponent) {
- if (!PrevComponent.empty())
- OS << "DIAG_COMPAT_IDS_END()\n";
- OS << "DIAG_COMPAT_IDS_BEGIN()\n";
- PrevComponent = DiagComponent;
- }
-
- // FIXME: We sometimes define multiple compat diagnostics with the same
- // name, e.g. 'constexpr_body_invalid_stmt' exists for C++14/20/23. It would
- // be nice if we could combine all of them into a single compatibility diag
- // id.
- OS << "DIAG_COMPAT_ID(" << I << ",";
- OS << CompatDiagName << "," << CXXStdVer << "," << Diag << "," << DiagPre;
- OS << ")\n";
- }
-
- if (!PrevComponent.empty())
- OS << "DIAG_COMPAT_IDS_END()\n";
-}
-
/// ClangDiagsEnumsEmitter - The top-level class emits .def files containing
/// declarations of Clang diagnostic enums for selects.
void clang::EmitClangDiagsEnums(const RecordKeeper &Records, raw_ostream &OS,
diff --git a/clang/utils/TableGen/TableGen.cpp b/clang/utils/TableGen/TableGen.cpp
index 4d3d56e..7ffe6d2 100644
--- a/clang/utils/TableGen/TableGen.cpp
+++ b/clang/utils/TableGen/TableGen.cpp
@@ -48,7 +48,6 @@
GenClangBasicWriter,
GenClangBuiltins,
GenClangBuiltinTemplates,
- GenClangDiagsCompatIDs,
GenClangDiagsDefs,
GenClangDiagsEnums,
GenClangDiagGroups,
@@ -177,8 +176,6 @@
"Generate clang builtins list"),
clEnumValN(GenClangBuiltinTemplates, "gen-clang-builtin-templates",
"Generate clang builtins list"),
- clEnumValN(GenClangDiagsCompatIDs, "gen-clang-diags-compat-ids",
- "Generate Clang diagnostic compatibility ids"),
clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
"Generate Clang diagnostics definitions"),
clEnumValN(GenClangDiagsEnums, "gen-clang-diags-enums",
@@ -402,9 +399,6 @@
case GenClangBuiltinTemplates:
EmitClangBuiltinTemplates(Records, OS);
break;
- case GenClangDiagsCompatIDs:
- EmitClangDiagsCompatIDs(Records, OS, ClangComponent);
- break;
case GenClangDiagsDefs:
EmitClangDiagsDefs(Records, OS, ClangComponent);
break;
diff --git a/clang/utils/TableGen/TableGenBackends.h b/clang/utils/TableGen/TableGenBackends.h
index c26ce28..ae8ea3a 100644
--- a/clang/utils/TableGen/TableGenBackends.h
+++ b/clang/utils/TableGen/TableGenBackends.h
@@ -91,9 +91,6 @@
void EmitClangBuiltinTemplates(const llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
-void EmitClangDiagsCompatIDs(const llvm::RecordKeeper &Records,
- llvm::raw_ostream &OS,
- const std::string &Component);
void EmitClangDiagsDefs(const llvm::RecordKeeper &Records,
llvm::raw_ostream &OS, const std::string &Component);
void EmitClangDiagsEnums(const llvm::RecordKeeper &Records,