Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ macro(clang_diag_gen component)
-gen-clang-diags-defs -clang-component=${component}
SOURCE Diagnostic.td
TARGET ClangDiagnostic${component})

clang_tablegen(Diagnostic${component}Enums.inc
-gen-clang-diags-enums -clang-component=${component}
SOURCE Diagnostic.td
TARGET ClangDiagnostic${component}Enums)
endmacro(clang_diag_gen)

clang_diag_gen(Analysis)
Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_AST_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticASTEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/Basic/DiagnosticAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ enum {
#undef DIAG
NUM_BUILTIN_ANALYSIS_DIAGNOSTICS
};
#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticAnalysisEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticComment.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_COMMENT_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticCommentEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticCrossTU.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_CROSSTU_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticCrossTUEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_DRIVER_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticDriverEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticFrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_FRONTEND_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticFrontendEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticInstallAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ enum {
#undef DIAG
NUM_BUILTIN_INSTALLAPI_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticInstallAPIEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // namespace diag
} // namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
12 changes: 12 additions & 0 deletions clang/include/clang/Basic/DiagnosticLex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ enum {
#undef DIAG
NUM_BUILTIN_LEX_DIAGNOSTICS
};
#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticLexEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_PARSE_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticParseEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticRefactoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_REFACTORING_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticRefactoringEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticSema.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_SEMA_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticSemaEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,11 @@ def err_ambiguous_inherited_constructor : Error<
"constructor of %0 inherited from multiple base class subobjects">;
def note_ambiguous_inherited_constructor_using : Note<
"inherited from base class %0 here">;
def note_using_decl_class_member_workaround : Note<
"use %select{an alias declaration|a typedef declaration|a reference|"
"a const variable|a constexpr variable}0 instead">;
def note_using_decl_class_member_workaround
: Note<"use %enum_select<MemClassWorkaround>{%AliasDecl{an alias "
"declaration}|%TypedefDecl{a typedef declaration}|%ReferenceDecl{a "
"reference}|%ConstVar{a const variable}|%ConstexprVar{a constexpr "
"variable}}0 instead">;
def err_using_decl_can_not_refer_to_namespace : Error<
"using declaration cannot refer to a namespace">;
def note_namespace_using_decl : Note<
Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Basic/DiagnosticSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ enum {
#undef DIAG
NUM_BUILTIN_SERIALIZATION_DIAGNOSTICS
};

#define DIAG_ENUM(ENUM_NAME) \
namespace ENUM_NAME { \
enum {
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
#define DIAG_ENUM_END() \
} \
; \
}
#include "clang/Basic/DiagnosticSerializationEnums.inc"
#undef DIAG_ENUM_END
#undef DIAG_ENUM_ITEM
#undef DIAG_ENUM
} // end namespace diag
} // end namespace clang

Expand Down
25 changes: 13 additions & 12 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13217,18 +13217,18 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename,
if (getLangOpts().CPlusPlus11) {
// Convert 'using X::Y;' to 'using Y = X::Y;'.
Diag(SS.getBeginLoc(), diag::note_using_decl_class_member_workaround)
<< 0 // alias declaration
<< FixItHint::CreateInsertion(SS.getBeginLoc(),
NameInfo.getName().getAsString() +
" = ");
<< diag::MemClassWorkaround::AliasDecl
<< FixItHint::CreateInsertion(SS.getBeginLoc(),
NameInfo.getName().getAsString() +
" = ");
} else {
// Convert 'using X::Y;' to 'typedef X::Y Y;'.
SourceLocation InsertLoc = getLocForEndOfToken(NameInfo.getEndLoc());
Diag(InsertLoc, diag::note_using_decl_class_member_workaround)
<< 1 // typedef declaration
<< FixItHint::CreateReplacement(UsingLoc, "typedef")
<< FixItHint::CreateInsertion(
InsertLoc, " " + NameInfo.getName().getAsString());
<< diag::MemClassWorkaround::TypedefDecl
<< FixItHint::CreateReplacement(UsingLoc, "typedef")
<< FixItHint::CreateInsertion(
InsertLoc, " " + NameInfo.getName().getAsString());
}
} else if (R->getAsSingle<VarDecl>()) {
// Don't provide a fixit outside C++11 mode; we don't want to suggest
Expand All @@ -13241,8 +13241,7 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename,
}

Diag(UsingLoc, diag::note_using_decl_class_member_workaround)
<< 2 // reference declaration
<< FixIt;
<< diag::MemClassWorkaround::ReferenceDecl << FixIt;
} else if (R->getAsSingle<EnumConstantDecl>()) {
// Don't provide a fixit outside C++11 mode; we don't want to suggest
// repeating the type of the enumeration here, and we can't do so if
Expand All @@ -13256,8 +13255,10 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename,
}

Diag(UsingLoc, diag::note_using_decl_class_member_workaround)
<< (getLangOpts().CPlusPlus11 ? 4 : 3) // const[expr] variable
<< FixIt;
<< (getLangOpts().CPlusPlus11
? diag::MemClassWorkaround::ConstexprVar
: diag::MemClassWorkaround::ConstVar)
<< FixIt;
}
}

Expand Down
16 changes: 16 additions & 0 deletions clang/test/TableGen/select-enum-errors.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: clang-tblgen --gen-clang-diags-enums -I%S %s 2>&1 | FileCheck %s
include "DiagnosticBase.inc"

def DupeNames1 : Error<"%enum_select<DupeName>{}0">;
def DupeNames2 : Error<"%enum_select<DupeName>{}0">;
// CHECK: error: Duplicate enumeration name 'DupeName'
// CHECK-NEXT: def DupeNames2
// CHECK: note: Previous diagnostic is here
// CHECK-NEXT: def DupeNames1

def DupeValue : Error<"%enum_select<DupeValue>{%Name{V1}|%Name{V2}}0">;
// CHECK: error: Duplicate enumerator name 'Name'

def EnumValNotExpected : Error<"%enum_select{V1|%Val2{V2}}0">;
// CHECK: expected '<' after enum_select

26 changes: 26 additions & 0 deletions clang/test/TableGen/select-enum.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: clang-tblgen --gen-clang-diags-enums -I%S %s 2>&1 | FileCheck %s
include "DiagnosticBase.inc"

def Diag : Error<"%enum_select<EnumName>{%Val1{V1}|%Val2{V2}|%Val3{V3}}0">;
// CHECK: DIAG_ENUM(EnumName)
// CHECK-NEXT: DIAG_ENUM_ITEM(0, Val1)
// CHECK-NEXT: DIAG_ENUM_ITEM(1, Val2)
// CHECK-NEXT: DIAG_ENUM_ITEM(2, Val3)
// CHECK-NEXT: DIAG_ENUM_END()

// These are OK, we permit missing values since they might not be useful.
def Missing1 : Error<"%enum_select<DupeEnumName1>{V1|%Val2{V2}|%Val3{V3}}0">;
// CHECK: DIAG_ENUM(DupeEnumName1)
// CHECK-NEXT: DIAG_ENUM_ITEM(1, Val2)
// CHECK-NEXT: DIAG_ENUM_ITEM(2, Val3)
// CHECK-NEXT: DIAG_ENUM_END()
def Missing2 : Error<"%enum_select<DupeEnumName2>{%Val1{V1}|V2|%Val3{V3}}0">;
// CHECK: DIAG_ENUM(DupeEnumName2)
// CHECK-NEXT: DIAG_ENUM_ITEM(0, Val1)
// CHECK-NEXT: DIAG_ENUM_ITEM(2, Val3)
// CHECK-NEXT: DIAG_ENUM_END()
def Missing3 : Error<"%enum_select<DupeEnumName3>{%Val1{V1}|%Val2{V2}|V3}0">;
// CHECK: DIAG_ENUM(DupeEnumName3)
// CHECK-NEXT: DIAG_ENUM_ITEM(0, Val1)
// CHECK-NEXT: DIAG_ENUM_ITEM(1, Val2)
// CHECK-NEXT: DIAG_ENUM_END()
Loading
Loading