Skip to content

Commit 08f8efd

Browse files
authored
Revert "[clang] Add scoped enum support to StreamingDiagnostic (#138089)"
This reverts commit 001cc34.
1 parent b6f65f0 commit 08f8efd

25 files changed

+125
-105
lines changed

clang/include/clang/Basic/Diagnostic.h

-16
Original file line numberDiff line numberDiff line change
@@ -1429,22 +1429,6 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
14291429
return DB;
14301430
}
14311431

1432-
// Convert scope enums to their underlying type, so that we don't have
1433-
// clutter the emitting code with `llvm::to_underlying()`.
1434-
// We also need to disable implicit conversion for the first argument,
1435-
// because classes that derive from StreamingDiagnostic define their own
1436-
// templated operator<< that accept a wide variety of types, leading
1437-
// to ambiguity.
1438-
template <typename T, typename U>
1439-
inline std::enable_if_t<
1440-
std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
1441-
llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
1442-
const StreamingDiagnostic &>
1443-
operator<<(const T &DB, U &&SE) {
1444-
DB << llvm::to_underlying(SE);
1445-
return DB;
1446-
}
1447-
14481432
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
14491433
SourceLocation L) {
14501434
DB.AddSourceRange(CharSourceRange::getTokenRange(L));

clang/include/clang/Sema/Sema.h

+11
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ enum class AssignmentAction {
220220
Casting,
221221
Passing_CFAudited
222222
};
223+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
224+
const AssignmentAction &AA) {
225+
DB << llvm::to_underlying(AA);
226+
return DB;
227+
}
223228

224229
namespace threadSafety {
225230
class BeforeSet;
@@ -15466,6 +15471,12 @@ void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
1546615471
llvm::StringRef StackSlotLabel,
1546715472
AlignPackInfo Value);
1546815473

15474+
inline const StreamingDiagnostic &
15475+
operator<<(const StreamingDiagnostic &DB, Sema::StringEvaluationContext Ctx) {
15476+
DB << llvm::to_underlying(Ctx);
15477+
return DB;
15478+
}
15479+
1546915480
} // end namespace clang
1547015481

1547115482
#endif

clang/lib/AST/ODRDiagsEmitter.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,10 @@ bool ODRDiagsEmitter::diagnoseSubMismatchObjCMethod(
461461
}
462462
if (FirstMethod->getImplementationControl() !=
463463
SecondMethod->getImplementationControl()) {
464-
DiagError(ControlLevel) << FirstMethod->getImplementationControl();
465-
DiagNote(ControlLevel) << SecondMethod->getImplementationControl();
464+
DiagError(ControlLevel)
465+
<< llvm::to_underlying(FirstMethod->getImplementationControl());
466+
DiagNote(ControlLevel) << llvm::to_underlying(
467+
SecondMethod->getImplementationControl());
466468
return true;
467469
}
468470
if (FirstMethod->isThisDeclarationADesignatedInitializer() !=

clang/lib/Parse/ParseDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
25782578
if (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate &&
25792579
D.isFirstDeclarator()) {
25802580
Diag(CommaLoc, diag::err_multiple_template_declarators)
2581-
<< TemplateInfo.Kind;
2581+
<< llvm::to_underlying(TemplateInfo.Kind);
25822582
}
25832583

25842584
// Parse the next declarator.

clang/lib/Parse/ParseDeclCXX.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3472,7 +3472,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
34723472
if (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate &&
34733473
DeclaratorInfo.isFirstDeclarator()) {
34743474
Diag(CommaLoc, diag::err_multiple_template_declarators)
3475-
<< TemplateInfo.Kind;
3475+
<< llvm::to_underlying(TemplateInfo.Kind);
34763476
}
34773477

34783478
// Parse the next declarator.

clang/lib/Parse/ParsePragma.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2341,8 +2341,7 @@ void PragmaClangSectionHandler::HandlePragma(Preprocessor &PP,
23412341
SourceLocation PragmaLocation = Tok.getLocation();
23422342
PP.Lex(Tok); // eat ['bss'|'data'|'rodata'|'text']
23432343
if (Tok.isNot(tok::equal)) {
2344-
PP.Diag(Tok.getLocation(), diag::err_pragma_clang_section_expected_equal)
2345-
<< SecKind;
2344+
PP.Diag(Tok.getLocation(), diag::err_pragma_clang_section_expected_equal) << llvm::to_underlying(SecKind);
23462345
return;
23472346
}
23482347

clang/lib/Parse/Parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST TST) {
226226

227227
if (Kind != ExtraSemiKind::AfterMemberFunctionDefinition || HadMultipleSemis)
228228
Diag(StartLoc, diag::ext_extra_semi)
229-
<< Kind
229+
<< llvm::to_underlying(Kind)
230230
<< DeclSpec::getSpecifierName(
231231
TST, Actions.getASTContext().getPrintingPolicy())
232232
<< FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));

clang/lib/Sema/SemaAccess.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1670,21 +1670,24 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
16701670
case InitializedEntity::EK_Base:
16711671
PD = PDiag(diag::err_access_base_ctor);
16721672
PD << Entity.isInheritedVirtualBase()
1673-
<< Entity.getBaseSpecifier()->getType() << getSpecialMember(Constructor);
1673+
<< Entity.getBaseSpecifier()->getType()
1674+
<< llvm::to_underlying(getSpecialMember(Constructor));
16741675
break;
16751676

16761677
case InitializedEntity::EK_Member:
16771678
case InitializedEntity::EK_ParenAggInitMember: {
16781679
const FieldDecl *Field = cast<FieldDecl>(Entity.getDecl());
16791680
PD = PDiag(diag::err_access_field_ctor);
1680-
PD << Field->getType() << getSpecialMember(Constructor);
1681+
PD << Field->getType()
1682+
<< llvm::to_underlying(getSpecialMember(Constructor));
16811683
break;
16821684
}
16831685

16841686
case InitializedEntity::EK_LambdaCapture: {
16851687
StringRef VarName = Entity.getCapturedVarName();
16861688
PD = PDiag(diag::err_access_lambda_capture);
1687-
PD << VarName << Entity.getType() << getSpecialMember(Constructor);
1689+
PD << VarName << Entity.getType()
1690+
<< llvm::to_underlying(getSpecialMember(Constructor));
16881691
break;
16891692
}
16901693

clang/lib/Sema/SemaCUDA.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
450450
if (Diagnose) {
451451
Diag(ClassDecl->getLocation(),
452452
diag::note_implicit_member_target_infer_collision)
453-
<< (unsigned)CSM << *InferredTarget << BaseMethodTarget;
453+
<< (unsigned)CSM << llvm::to_underlying(*InferredTarget)
454+
<< llvm::to_underlying(BaseMethodTarget);
454455
}
455456
MemberDecl->addAttr(
456457
CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -495,7 +496,8 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
495496
if (Diagnose) {
496497
Diag(ClassDecl->getLocation(),
497498
diag::note_implicit_member_target_infer_collision)
498-
<< (unsigned)CSM << *InferredTarget << FieldMethodTarget;
499+
<< (unsigned)CSM << llvm::to_underlying(*InferredTarget)
500+
<< llvm::to_underlying(FieldMethodTarget);
499501
}
500502
MemberDecl->addAttr(
501503
CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -711,7 +713,7 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) {
711713
if (InitFnTarget != CUDAFunctionTarget::Host &&
712714
InitFnTarget != CUDAFunctionTarget::HostDevice) {
713715
Diag(VD->getLocation(), diag::err_ref_bad_target_global_initializer)
714-
<< InitFnTarget << InitFn;
716+
<< llvm::to_underlying(InitFnTarget) << InitFn;
715717
Diag(InitFn->getLocation(), diag::note_previous_decl) << InitFn;
716718
VD->setInvalidDecl();
717719
}
@@ -950,8 +952,8 @@ bool SemaCUDA::CheckCall(SourceLocation Loc, FunctionDecl *Callee) {
950952

951953
SemaDiagnosticBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller,
952954
SemaRef)
953-
<< IdentifyTarget(Callee) << /*function*/ 0 << Callee
954-
<< IdentifyTarget(Caller);
955+
<< llvm::to_underlying(IdentifyTarget(Callee)) << /*function*/ 0 << Callee
956+
<< llvm::to_underlying(IdentifyTarget(Caller));
955957
if (!Callee->getBuiltinID())
956958
SemaDiagnosticBuilder(DiagKind, Callee->getLocation(),
957959
diag::note_previous_decl, Caller, SemaRef)
@@ -1047,7 +1049,8 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
10471049
(NewTarget == CUDAFunctionTarget::Global) ||
10481050
(OldTarget == CUDAFunctionTarget::Global)) {
10491051
Diag(NewFD->getLocation(), diag::err_cuda_ovl_target)
1050-
<< NewTarget << NewFD->getDeclName() << OldTarget << OldFD;
1052+
<< llvm::to_underlying(NewTarget) << NewFD->getDeclName()
1053+
<< llvm::to_underlying(OldTarget) << OldFD;
10511054
Diag(OldFD->getLocation(), diag::note_previous_declaration);
10521055
NewFD->setInvalidDecl();
10531056
break;
@@ -1057,7 +1060,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
10571060
(NewTarget == CUDAFunctionTarget::Device &&
10581061
OldTarget == CUDAFunctionTarget::Host)) {
10591062
Diag(NewFD->getLocation(), diag::warn_offload_incompatible_redeclare)
1060-
<< NewTarget << OldTarget;
1063+
<< llvm::to_underlying(NewTarget) << llvm::to_underlying(OldTarget);
10611064
Diag(OldFD->getLocation(), diag::note_previous_declaration);
10621065
}
10631066
}

clang/lib/Sema/SemaChecking.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -8339,7 +8339,8 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83398339
} else {
83408340
EmitFormatDiagnostic(
83418341
S.PDiag(diag::warn_non_pod_vararg_with_format_string)
8342-
<< S.getLangOpts().CPlusPlus11 << ExprTy << CallType
8342+
<< S.getLangOpts().CPlusPlus11 << ExprTy
8343+
<< llvm::to_underlying(CallType)
83438344
<< AT.getRepresentativeTypeName(S.Context) << CSR
83448345
<< E->getSourceRange(),
83458346
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8353,15 +8354,16 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83538354
else if (ExprTy->isObjCObjectType())
83548355
EmitFormatDiagnostic(
83558356
S.PDiag(diag::err_cannot_pass_objc_interface_to_vararg_format)
8356-
<< S.getLangOpts().CPlusPlus11 << ExprTy << CallType
8357+
<< S.getLangOpts().CPlusPlus11 << ExprTy
8358+
<< llvm::to_underlying(CallType)
83578359
<< AT.getRepresentativeTypeName(S.Context) << CSR
83588360
<< E->getSourceRange(),
83598361
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
83608362
else
83618363
// FIXME: If this is an initializer list, suggest removing the braces
83628364
// or inserting a cast to the target type.
83638365
S.Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg_format)
8364-
<< isa<InitListExpr>(E) << ExprTy << CallType
8366+
<< isa<InitListExpr>(E) << ExprTy << llvm::to_underlying(CallType)
83658367
<< AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
83668368
break;
83678369
}

clang/lib/Sema/SemaDecl.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -4034,13 +4034,13 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
40344034
} else {
40354035
Diag(NewMethod->getLocation(),
40364036
diag::err_definition_of_implicitly_declared_member)
4037-
<< New << getSpecialMember(OldMethod);
4037+
<< New << llvm::to_underlying(getSpecialMember(OldMethod));
40384038
return true;
40394039
}
40404040
} else if (OldMethod->getFirstDecl()->isExplicitlyDefaulted() && !isFriend) {
40414041
Diag(NewMethod->getLocation(),
40424042
diag::err_definition_of_explicitly_defaulted_member)
4043-
<< getSpecialMember(OldMethod);
4043+
<< llvm::to_underlying(getSpecialMember(OldMethod));
40444044
return true;
40454045
}
40464046
}
@@ -5249,7 +5249,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
52495249
if (DS.isModulePrivateSpecified() &&
52505250
Tag && Tag->getDeclContext()->isFunctionOrMethod())
52515251
Diag(DS.getModulePrivateSpecLoc(), diag::err_module_private_local_class)
5252-
<< Tag->getTagKind()
5252+
<< llvm::to_underlying(Tag->getTagKind())
52535253
<< FixItHint::CreateRemoval(DS.getModulePrivateSpecLoc());
52545254

52555255
ActOnDocumentableDecl(TagD);
@@ -7722,14 +7722,15 @@ NamedDecl *Sema::ActOnVariableDeclarator(
77227722
// data members.
77237723
Diag(D.getIdentifierLoc(),
77247724
diag::err_static_data_member_not_allowed_in_local_class)
7725-
<< Name << RD->getDeclName() << RD->getTagKind();
7725+
<< Name << RD->getDeclName()
7726+
<< llvm::to_underlying(RD->getTagKind());
77267727
} else if (AnonStruct) {
77277728
// C++ [class.static.data]p4: Unnamed classes and classes contained
77287729
// directly or indirectly within unnamed classes shall not contain
77297730
// static data members.
77307731
Diag(D.getIdentifierLoc(),
77317732
diag::err_static_data_member_not_allowed_in_anon_struct)
7732-
<< Name << AnonStruct->getTagKind();
7733+
<< Name << llvm::to_underlying(AnonStruct->getTagKind());
77337734
Invalid = true;
77347735
} else if (RD->isUnion()) {
77357736
// C++98 [class.union]p1: If a union contains a static data member,
@@ -17660,7 +17661,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1766017661

1766117662
// A tag 'foo::bar' must already exist.
1766217663
Diag(NameLoc, diag::err_not_tag_in_scope)
17663-
<< Kind << Name << DC << SS.getRange();
17664+
<< llvm::to_underlying(Kind) << Name << DC << SS.getRange();
1766417665
Name = nullptr;
1766517666
Invalid = true;
1766617667
goto CreateNewDecl;
@@ -18118,7 +18119,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1811818119
!Previous.isForRedeclaration()) {
1811918120
NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl, Kind);
1812018121
Diag(NameLoc, diag::err_tag_reference_non_tag)
18121-
<< PrevDecl << NTK << Kind;
18122+
<< PrevDecl << NTK << llvm::to_underlying(Kind);
1812218123
Diag(PrevDecl->getLocation(), diag::note_declared_at);
1812318124
Invalid = true;
1812418125

@@ -19017,7 +19018,8 @@ bool Sema::CheckNontrivialField(FieldDecl *FD) {
1901719018
getLangOpts().CPlusPlus11
1901819019
? diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member
1901919020
: diag::err_illegal_union_or_anon_struct_member)
19020-
<< FD->getParent()->isUnion() << FD->getDeclName() << member;
19021+
<< FD->getParent()->isUnion() << FD->getDeclName()
19022+
<< llvm::to_underlying(member);
1902119023
DiagnoseNontrivial(RDecl, member);
1902219024
return !getLangOpts().CPlusPlus11;
1902319025
}
@@ -19357,7 +19359,8 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1935719359
unsigned DiagID = 0;
1935819360
if (!Record->isUnion() && !IsLastField) {
1935919361
Diag(FD->getLocation(), diag::err_flexible_array_not_at_end)
19360-
<< FD->getDeclName() << FD->getType() << Record->getTagKind();
19362+
<< FD->getDeclName() << FD->getType()
19363+
<< llvm::to_underlying(Record->getTagKind());
1936119364
Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
1936219365
FD->setInvalidDecl();
1936319366
EnclosingDecl->setInvalidDecl();
@@ -19373,18 +19376,18 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1937319376

1937419377
if (DiagID)
1937519378
Diag(FD->getLocation(), DiagID)
19376-
<< FD->getDeclName() << Record->getTagKind();
19379+
<< FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
1937719380
// While the layout of types that contain virtual bases is not specified
1937819381
// by the C++ standard, both the Itanium and Microsoft C++ ABIs place
1937919382
// virtual bases after the derived members. This would make a flexible
1938019383
// array member declared at the end of an object not adjacent to the end
1938119384
// of the type.
1938219385
if (CXXRecord && CXXRecord->getNumVBases() != 0)
1938319386
Diag(FD->getLocation(), diag::err_flexible_array_virtual_base)
19384-
<< FD->getDeclName() << Record->getTagKind();
19387+
<< FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
1938519388
if (!getLangOpts().C99)
1938619389
Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
19387-
<< FD->getDeclName() << Record->getTagKind();
19390+
<< FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
1938819391

1938919392
// If the element type has a non-trivial destructor, we would not
1939019393
// implicitly destroy the elements, so disallow it for now.

clang/lib/Sema/SemaDeclAttr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5058,7 +5058,7 @@ static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
50585058
}
50595059
if (S.getLangOpts().CUDA && VD->hasLocalStorage() &&
50605060
S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
5061-
<< S.CUDA().CurrentTarget())
5061+
<< llvm::to_underlying(S.CUDA().CurrentTarget()))
50625062
return;
50635063
D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
50645064
}

0 commit comments

Comments
 (0)