aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorVlad Serebrennikov <serebrennikov.vladislav@gmail.com>2025-05-01 17:03:47 +0400
committerGitHub <noreply@github.com>2025-05-01 17:03:47 +0400
commit001cc34275111df842edbaa874b7319eef930c81 (patch)
tree73c89d65330a850bc2a2b9718e5bdcc5c27c6e22 /clang/lib/Sema
parenta6459debc06f9cb86940ff5cdae35a1f52e1ed19 (diff)
downloadllvm-001cc34275111df842edbaa874b7319eef930c81.zip
llvm-001cc34275111df842edbaa874b7319eef930c81.tar.gz
llvm-001cc34275111df842edbaa874b7319eef930c81.tar.bz2
[clang] Add scoped enum support to `StreamingDiagnostic` (#138089)
This patch adds templated `operator<<` for diagnostics that pass scoped enums, saving people from `llvm::to_underlying()` clutter on the side of emitting the diagnostic. This eliminates 80 out of 220 usages of `llvm::to_underlying()` in Clang. I also backported `std::is_scoped_enum_v` from C++23.
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaAccess.cpp9
-rw-r--r--clang/lib/Sema/SemaCUDA.cpp17
-rw-r--r--clang/lib/Sema/SemaChecking.cpp8
-rw-r--r--clang/lib/Sema/SemaDecl.cpp27
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp2
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp62
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp2
-rw-r--r--clang/lib/Sema/SemaExpr.cpp18
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp2
-rw-r--r--clang/lib/Sema/SemaInit.cpp3
-rw-r--r--clang/lib/Sema/SemaOverload.cpp5
-rw-r--r--clang/lib/Sema/SemaStmt.cpp2
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp8
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp5
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp4
-rw-r--r--clang/lib/Sema/SemaType.cpp2
-rw-r--r--clang/lib/Sema/TreeTransform.h8
17 files changed, 78 insertions, 106 deletions
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index b77cbdb..890df09 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -1670,24 +1670,21 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
case InitializedEntity::EK_Base:
PD = PDiag(diag::err_access_base_ctor);
PD << Entity.isInheritedVirtualBase()
- << Entity.getBaseSpecifier()->getType()
- << llvm::to_underlying(getSpecialMember(Constructor));
+ << Entity.getBaseSpecifier()->getType() << getSpecialMember(Constructor);
break;
case InitializedEntity::EK_Member:
case InitializedEntity::EK_ParenAggInitMember: {
const FieldDecl *Field = cast<FieldDecl>(Entity.getDecl());
PD = PDiag(diag::err_access_field_ctor);
- PD << Field->getType()
- << llvm::to_underlying(getSpecialMember(Constructor));
+ PD << Field->getType() << getSpecialMember(Constructor);
break;
}
case InitializedEntity::EK_LambdaCapture: {
StringRef VarName = Entity.getCapturedVarName();
PD = PDiag(diag::err_access_lambda_capture);
- PD << VarName << Entity.getType()
- << llvm::to_underlying(getSpecialMember(Constructor));
+ PD << VarName << Entity.getType() << getSpecialMember(Constructor);
break;
}
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 0a8c24f..4559506 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -450,8 +450,7 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
if (Diagnose) {
Diag(ClassDecl->getLocation(),
diag::note_implicit_member_target_infer_collision)
- << (unsigned)CSM << llvm::to_underlying(*InferredTarget)
- << llvm::to_underlying(BaseMethodTarget);
+ << (unsigned)CSM << *InferredTarget << BaseMethodTarget;
}
MemberDecl->addAttr(
CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -496,8 +495,7 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
if (Diagnose) {
Diag(ClassDecl->getLocation(),
diag::note_implicit_member_target_infer_collision)
- << (unsigned)CSM << llvm::to_underlying(*InferredTarget)
- << llvm::to_underlying(FieldMethodTarget);
+ << (unsigned)CSM << *InferredTarget << FieldMethodTarget;
}
MemberDecl->addAttr(
CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -713,7 +711,7 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) {
if (InitFnTarget != CUDAFunctionTarget::Host &&
InitFnTarget != CUDAFunctionTarget::HostDevice) {
Diag(VD->getLocation(), diag::err_ref_bad_target_global_initializer)
- << llvm::to_underlying(InitFnTarget) << InitFn;
+ << InitFnTarget << InitFn;
Diag(InitFn->getLocation(), diag::note_previous_decl) << InitFn;
VD->setInvalidDecl();
}
@@ -952,8 +950,8 @@ bool SemaCUDA::CheckCall(SourceLocation Loc, FunctionDecl *Callee) {
SemaDiagnosticBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller,
SemaRef)
- << llvm::to_underlying(IdentifyTarget(Callee)) << /*function*/ 0 << Callee
- << llvm::to_underlying(IdentifyTarget(Caller));
+ << IdentifyTarget(Callee) << /*function*/ 0 << Callee
+ << IdentifyTarget(Caller);
if (!Callee->getBuiltinID())
SemaDiagnosticBuilder(DiagKind, Callee->getLocation(),
diag::note_previous_decl, Caller, SemaRef)
@@ -1049,8 +1047,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
(NewTarget == CUDAFunctionTarget::Global) ||
(OldTarget == CUDAFunctionTarget::Global)) {
Diag(NewFD->getLocation(), diag::err_cuda_ovl_target)
- << llvm::to_underlying(NewTarget) << NewFD->getDeclName()
- << llvm::to_underlying(OldTarget) << OldFD;
+ << NewTarget << NewFD->getDeclName() << OldTarget << OldFD;
Diag(OldFD->getLocation(), diag::note_previous_declaration);
NewFD->setInvalidDecl();
break;
@@ -1060,7 +1057,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
(NewTarget == CUDAFunctionTarget::Device &&
OldTarget == CUDAFunctionTarget::Host)) {
Diag(NewFD->getLocation(), diag::warn_offload_incompatible_redeclare)
- << llvm::to_underlying(NewTarget) << llvm::to_underlying(OldTarget);
+ << NewTarget << OldTarget;
Diag(OldFD->getLocation(), diag::note_previous_declaration);
}
}
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2d64889..92ec2fe 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8339,8 +8339,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
} else {
EmitFormatDiagnostic(
S.PDiag(diag::warn_non_pod_vararg_with_format_string)
- << S.getLangOpts().CPlusPlus11 << ExprTy
- << llvm::to_underlying(CallType)
+ << S.getLangOpts().CPlusPlus11 << ExprTy << CallType
<< AT.getRepresentativeTypeName(S.Context) << CSR
<< E->getSourceRange(),
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8354,8 +8353,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
else if (ExprTy->isObjCObjectType())
EmitFormatDiagnostic(
S.PDiag(diag::err_cannot_pass_objc_interface_to_vararg_format)
- << S.getLangOpts().CPlusPlus11 << ExprTy
- << llvm::to_underlying(CallType)
+ << S.getLangOpts().CPlusPlus11 << ExprTy << CallType
<< AT.getRepresentativeTypeName(S.Context) << CSR
<< E->getSourceRange(),
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8363,7 +8361,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
// FIXME: If this is an initializer list, suggest removing the braces
// or inserting a cast to the target type.
S.Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg_format)
- << isa<InitListExpr>(E) << ExprTy << llvm::to_underlying(CallType)
+ << isa<InitListExpr>(E) << ExprTy << CallType
<< AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
break;
}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 517b3067..a3285e8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4034,13 +4034,13 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
} else {
Diag(NewMethod->getLocation(),
diag::err_definition_of_implicitly_declared_member)
- << New << llvm::to_underlying(getSpecialMember(OldMethod));
+ << New << getSpecialMember(OldMethod);
return true;
}
} else if (OldMethod->getFirstDecl()->isExplicitlyDefaulted() && !isFriend) {
Diag(NewMethod->getLocation(),
diag::err_definition_of_explicitly_defaulted_member)
- << llvm::to_underlying(getSpecialMember(OldMethod));
+ << getSpecialMember(OldMethod);
return true;
}
}
@@ -5249,7 +5249,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
if (DS.isModulePrivateSpecified() &&
Tag && Tag->getDeclContext()->isFunctionOrMethod())
Diag(DS.getModulePrivateSpecLoc(), diag::err_module_private_local_class)
- << llvm::to_underlying(Tag->getTagKind())
+ << Tag->getTagKind()
<< FixItHint::CreateRemoval(DS.getModulePrivateSpecLoc());
ActOnDocumentableDecl(TagD);
@@ -7722,15 +7722,14 @@ NamedDecl *Sema::ActOnVariableDeclarator(
// data members.
Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_local_class)
- << Name << RD->getDeclName()
- << llvm::to_underlying(RD->getTagKind());
+ << Name << RD->getDeclName() << RD->getTagKind();
} else if (AnonStruct) {
// C++ [class.static.data]p4: Unnamed classes and classes contained
// directly or indirectly within unnamed classes shall not contain
// static data members.
Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_anon_struct)
- << Name << llvm::to_underlying(AnonStruct->getTagKind());
+ << Name << AnonStruct->getTagKind();
Invalid = true;
} else if (RD->isUnion()) {
// C++98 [class.union]p1: If a union contains a static data member,
@@ -17661,7 +17660,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
// A tag 'foo::bar' must already exist.
Diag(NameLoc, diag::err_not_tag_in_scope)
- << llvm::to_underlying(Kind) << Name << DC << SS.getRange();
+ << Kind << Name << DC << SS.getRange();
Name = nullptr;
Invalid = true;
goto CreateNewDecl;
@@ -18119,7 +18118,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
!Previous.isForRedeclaration()) {
NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl, Kind);
Diag(NameLoc, diag::err_tag_reference_non_tag)
- << PrevDecl << NTK << llvm::to_underlying(Kind);
+ << PrevDecl << NTK << Kind;
Diag(PrevDecl->getLocation(), diag::note_declared_at);
Invalid = true;
@@ -19018,8 +19017,7 @@ bool Sema::CheckNontrivialField(FieldDecl *FD) {
getLangOpts().CPlusPlus11
? diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member
: diag::err_illegal_union_or_anon_struct_member)
- << FD->getParent()->isUnion() << FD->getDeclName()
- << llvm::to_underlying(member);
+ << FD->getParent()->isUnion() << FD->getDeclName() << member;
DiagnoseNontrivial(RDecl, member);
return !getLangOpts().CPlusPlus11;
}
@@ -19359,8 +19357,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
unsigned DiagID = 0;
if (!Record->isUnion() && !IsLastField) {
Diag(FD->getLocation(), diag::err_flexible_array_not_at_end)
- << FD->getDeclName() << FD->getType()
- << llvm::to_underlying(Record->getTagKind());
+ << FD->getDeclName() << FD->getType() << Record->getTagKind();
Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
@@ -19376,7 +19373,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
if (DiagID)
Diag(FD->getLocation(), DiagID)
- << FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
+ << FD->getDeclName() << Record->getTagKind();
// While the layout of types that contain virtual bases is not specified
// by the C++ standard, both the Itanium and Microsoft C++ ABIs place
// virtual bases after the derived members. This would make a flexible
@@ -19384,10 +19381,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
// of the type.
if (CXXRecord && CXXRecord->getNumVBases() != 0)
Diag(FD->getLocation(), diag::err_flexible_array_virtual_base)
- << FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
+ << FD->getDeclName() << Record->getTagKind();
if (!getLangOpts().C99)
Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
- << FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
+ << FD->getDeclName() << Record->getTagKind();
// If the element type has a non-trivial destructor, we would not
// implicitly destroy the elements, so disallow it for now.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ab66ae8..9d6a1c7 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5058,7 +5058,7 @@ static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
}
if (S.getLangOpts().CUDA && VD->hasLocalStorage() &&
S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
- << llvm::to_underlying(S.CUDA().CurrentTarget()))
+ << S.CUDA().CurrentTarget())
return;
D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
}
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 645a088..a7e6868 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -647,7 +647,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
ParmVarDecl *NewParam = New->getParamDecl(New->getMinRequiredArguments());
assert(NewParam->hasDefaultArg());
Diag(NewParam->getLocation(), diag::err_default_arg_makes_ctor_special)
- << NewParam->getDefaultArgRange() << llvm::to_underlying(NewSM);
+ << NewParam->getDefaultArgRange() << NewSM;
Diag(Old->getLocation(), diag::note_previous_declaration);
}
}
@@ -6978,7 +6978,7 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
(F->getType().isConstQualified() && F->getType()->isScalarType())) {
if (!Complained) {
Diag(Record->getLocation(), diag::warn_no_constructor_for_refconst)
- << llvm::to_underlying(Record->getTagKind()) << Record;
+ << Record->getTagKind() << Record;
Complained = true;
}
@@ -7774,14 +7774,14 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
// default argument is classified as a default constructor, and assignment
// operations and destructors can't have default arguments.
Diag(MD->getLocation(), diag::err_defaulted_special_member_params)
- << llvm::to_underlying(CSM) << MD->getSourceRange();
+ << CSM << MD->getSourceRange();
HadError = true;
} else if (MD->isVariadic()) {
if (DeleteOnTypeMismatch)
ShouldDeleteForTypeMismatch = true;
else {
Diag(MD->getLocation(), diag::err_defaulted_special_member_variadic)
- << llvm::to_underlying(CSM) << MD->getSourceRange();
+ << CSM << MD->getSourceRange();
HadError = true;
}
}
@@ -7868,7 +7868,7 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
else {
Diag(MD->getLocation(),
diag::err_defaulted_special_member_volatile_param)
- << llvm::to_underlying(CSM);
+ << CSM;
HadError = true;
}
}
@@ -7929,12 +7929,12 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
if (!MD->isConsteval() && RD->getNumVBases()) {
Diag(MD->getBeginLoc(),
diag::err_incorrect_defaulted_constexpr_with_vb)
- << llvm::to_underlying(CSM);
+ << CSM;
for (const auto &I : RD->vbases())
Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here);
} else {
Diag(MD->getBeginLoc(), diag::err_incorrect_defaulted_constexpr)
- << llvm::to_underlying(CSM) << MD->isConsteval();
+ << CSM << MD->isConsteval();
}
HadError = true;
// FIXME: Explain why the special member can't be constexpr.
@@ -7967,11 +7967,9 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
if (First) {
SetDeclDeleted(MD, MD->getLocation());
if (!inTemplateInstantiation() && !HadError) {
- Diag(MD->getLocation(), diag::warn_defaulted_method_deleted)
- << llvm::to_underlying(CSM);
+ Diag(MD->getLocation(), diag::warn_defaulted_method_deleted) << CSM;
if (ShouldDeleteForTypeMismatch) {
- Diag(MD->getLocation(), diag::note_deleted_type_mismatch)
- << llvm::to_underlying(CSM);
+ Diag(MD->getLocation(), diag::note_deleted_type_mismatch) << CSM;
} else if (ShouldDeleteSpecialMember(MD, CSM, nullptr,
/*Diagnose*/ true) &&
DefaultLoc.isValid()) {
@@ -7982,14 +7980,13 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
if (ShouldDeleteForTypeMismatch && !HadError) {
Diag(MD->getLocation(),
diag::warn_cxx17_compat_defaulted_method_type_mismatch)
- << llvm::to_underlying(CSM);
+ << CSM;
}
} else {
// C++11 [dcl.fct.def.default]p4:
// [For a] user-provided explicitly-defaulted function [...] if such a
// function is implicitly defined as deleted, the program is ill-formed.
- Diag(MD->getLocation(), diag::err_out_of_line_default_deletes)
- << llvm::to_underlying(CSM);
+ Diag(MD->getLocation(), diag::err_out_of_line_default_deletes) << CSM;
assert(!ShouldDeleteForTypeMismatch && "deleted non-first decl");
ShouldDeleteSpecialMember(MD, CSM, nullptr, /*Diagnose*/true);
HadError = true;
@@ -9555,16 +9552,15 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
if (Field) {
S.Diag(Field->getLocation(),
diag::note_deleted_special_member_class_subobject)
- << llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
- << /*IsField*/ true << Field << DiagKind << IsDtorCallInCtor
- << /*IsObjCPtr*/ false;
+ << getEffectiveCSM() << MD->getParent() << /*IsField*/ true << Field
+ << DiagKind << IsDtorCallInCtor << /*IsObjCPtr*/ false;
} else {
CXXBaseSpecifier *Base = cast<CXXBaseSpecifier *>(Subobj);
S.Diag(Base->getBeginLoc(),
diag::note_deleted_special_member_class_subobject)
- << llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
- << /*IsField*/ false << Base->getType() << DiagKind
- << IsDtorCallInCtor << /*IsObjCPtr*/ false;
+ << getEffectiveCSM() << MD->getParent() << /*IsField*/ false
+ << Base->getType() << DiagKind << IsDtorCallInCtor
+ << /*IsObjCPtr*/ false;
}
if (DiagKind == 1)
@@ -9633,9 +9629,8 @@ bool SpecialMemberDeletionInfo::shouldDeleteForVariantObjCPtrMember(
if (Diagnose) {
auto *ParentClass = cast<CXXRecordDecl>(FD->getParent());
S.Diag(FD->getLocation(), diag::note_deleted_special_member_class_subobject)
- << llvm::to_underlying(getEffectiveCSM()) << ParentClass
- << /*IsField*/ true << FD << 4 << /*IsDtorCallInCtor*/ false
- << /*IsObjCPtr*/ true;
+ << getEffectiveCSM() << ParentClass << /*IsField*/ true << FD << 4
+ << /*IsDtorCallInCtor*/ false << /*IsObjCPtr*/ true;
}
return true;
@@ -9658,8 +9653,8 @@ bool SpecialMemberDeletionInfo::shouldDeleteForVariantPtrAuthMember(
if (Diagnose) {
auto *ParentClass = cast<CXXRecordDecl>(FD->getParent());
S.Diag(FD->getLocation(), diag::note_deleted_special_member_class_subobject)
- << llvm::to_underlying(getEffectiveCSM()) << ParentClass
- << /*IsField*/ true << FD << 4 << /*IsDtorCallInCtor*/ false << 2;
+ << getEffectiveCSM() << ParentClass << /*IsField*/ true << FD << 4
+ << /*IsDtorCallInCtor*/ false << 2;
}
return true;
@@ -9684,9 +9679,9 @@ bool SpecialMemberDeletionInfo::shouldDeleteForBase(CXXBaseSpecifier *Base) {
if (BaseCtor->isDeleted() && Diagnose) {
S.Diag(Base->getBeginLoc(),
diag::note_deleted_special_member_class_subobject)
- << llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
- << /*IsField*/ false << Base->getType() << /*Deleted*/ 1
- << /*IsDtorCallInCtor*/ false << /*IsObjCPtr*/ false;
+ << getEffectiveCSM() << MD->getParent() << /*IsField*/ false
+ << Base->getType() << /*Deleted*/ 1 << /*IsDtorCallInCtor*/ false
+ << /*IsObjCPtr*/ false;
S.NoteDeletedFunction(BaseCtor);
}
return BaseCtor->isDeleted();
@@ -10182,21 +10177,20 @@ static bool checkTrivialSubobjectCall(Sema &S, SourceLocation SubobjLoc,
S.Diag(CD->getLocation(), diag::note_user_declared_ctor);
} else if (!Selected)
S.Diag(SubobjLoc, diag::note_nontrivial_no_copy)
- << Kind << SubType.getUnqualifiedType() << llvm::to_underlying(CSM)
- << SubType;
+ << Kind << SubType.getUnqualifiedType() << CSM << SubType;
else if (Selected->isUserProvided()) {
if (Kind == TSK_CompleteObject)
S.Diag(Selected->getLocation(), diag::note_nontrivial_user_provided)
- << Kind << SubType.getUnqualifiedType() << llvm::to_underlying(CSM);
+ << Kind << SubType.getUnqualifiedType() << CSM;
else {
S.Diag(SubobjLoc, diag::note_nontrivial_user_provided)
- << Kind << SubType.getUnqualifiedType() << llvm::to_underlying(CSM);
+ << Kind << SubType.getUnqualifiedType() << CSM;
S.Diag(Selected->getLocation(), diag::note_declared_at);
}
} else {
if (Kind != TSK_CompleteObject)
S.Diag(SubobjLoc, diag::note_nontrivial_subobject)
- << Kind << SubType.getUnqualifiedType() << llvm::to_underlying(CSM);
+ << Kind << SubType.getUnqualifiedType() << CSM;
// Explain why the defaulted or deleted special member isn't trivial.
S.SpecialMemberIsTrivial(Selected, CSM, Sema::TAH_IgnoreTrivialABI,
@@ -11471,7 +11465,7 @@ Decl *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
if (ConvType->isUndeducedAutoType()) {
Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
<< getReturnTypeLoc(Conversion).getSourceRange()
- << llvm::to_underlying(ConvType->castAs<AutoType>()->getKeyword())
+ << ConvType->castAs<AutoType>()->getKeyword()
<< /* in declaration of conversion function template= */ 24;
}
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 0a14ce2..501d441 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -3890,7 +3890,7 @@ static void DiagnoseVariableSizedIvars(Sema &S, ObjCContainerDecl *OCD) {
if (IvarTy->isIncompleteArrayType()) {
S.Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
<< ivar->getDeclName() << IvarTy
- << llvm::to_underlying(TagTypeKind::Class); // Use "class" for Obj-C.
+ << TagTypeKind::Class; // Use "class" for Obj-C.
IsInvalidIvar = true;
} else if (const RecordType *RecordTy = IvarTy->getAs<RecordType>()) {
if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b1cdf37..b686707 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1022,8 +1022,7 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
case VAK_ValidInCXX11:
DiagRuntimeBehavior(
E->getBeginLoc(), nullptr,
- PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg)
- << Ty << llvm::to_underlying(CT));
+ PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
[[fallthrough]];
case VAK_Valid:
if (Ty->isRecordType()) {
@@ -1031,8 +1030,7 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
// 'c_str' member function, the user probably meant to call that.
DiagRuntimeBehavior(E->getBeginLoc(), nullptr,
PDiag(diag::warn_pass_class_arg_to_vararg)
- << Ty << llvm::to_underlying(CT)
- << hasCStrMethod(E) << ".c_str()");
+ << Ty << CT << hasCStrMethod(E) << ".c_str()");
}
break;
@@ -1040,22 +1038,21 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
case VAK_MSVCUndefined:
DiagRuntimeBehavior(E->getBeginLoc(), nullptr,
PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
- << getLangOpts().CPlusPlus11 << Ty
- << llvm::to_underlying(CT));
+ << getLangOpts().CPlusPlus11 << Ty << CT);
break;
case VAK_Invalid:
if (Ty.isDestructedType() == QualType::DK_nontrivial_c_struct)
Diag(E->getBeginLoc(),
diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
- << Ty << llvm::to_underlying(CT);
+ << Ty << CT;
else if (Ty->isObjCObjectType())
DiagRuntimeBehavior(E->getBeginLoc(), nullptr,
PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
- << Ty << llvm::to_underlying(CT));
+ << Ty << CT);
else
Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg)
- << isa<InitListExpr>(E) << Ty << llvm::to_underlying(CT);
+ << isa<InitListExpr>(E) << Ty << CT;
break;
}
}
@@ -18557,8 +18554,7 @@ MarkVarDeclODRUsed(ValueDecl *V, SourceLocation Loc, Sema &SemaRef,
// through shadow variables therefore it is not diagnosed.
if (SemaRef.LangOpts.CUDAIsDevice && !SemaRef.LangOpts.HIPStdPar) {
SemaRef.targetDiag(Loc, diag::err_ref_bad_target)
- << /*host*/ 2 << /*variable*/ 1 << Var
- << llvm::to_underlying(UserTarget);
+ << /*host*/ 2 << /*variable*/ 1 << Var << UserTarget;
SemaRef.targetDiag(Var->getLocation(),
Var->getType().isConstQualified()
? diag::note_cuda_const_var_unpromoted
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 727eefa..09edc34 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -865,7 +865,7 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
// Exceptions aren't allowed in CUDA device code.
if (getLangOpts().CUDA)
CUDA().DiagIfDeviceCode(OpLoc, diag::err_cuda_device_exceptions)
- << "throw" << llvm::to_underlying(CUDA().CurrentTarget());
+ << "throw" << CUDA().CurrentTarget();
if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
Diag(OpLoc, diag::err_omp_simd_region_cannot_use_stmt) << "throw";
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 6900ccb..3737962 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9233,8 +9233,7 @@ bool InitializationSequence::Diagnose(Sema &S,
// implicit.
if (S.isImplicitlyDeleted(Best->Function))
S.Diag(Kind.getLocation(), diag::err_ovl_deleted_special_init)
- << llvm::to_underlying(
- S.getSpecialMember(cast<CXXMethodDecl>(Best->Function)))
+ << S.getSpecialMember(cast<CXXMethodDecl>(Best->Function))
<< DestType << ArgsRange;
else {
StringLiteral *Msg = Best->Function->getDeletedMessage();
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index b8c2356..7efd92b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12355,7 +12355,7 @@ static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) {
S.Diag(Callee->getLocation(), diag::note_ovl_candidate_bad_target)
<< (unsigned)FnKindPair.first << (unsigned)ocs_non_template
<< FnDesc /* Ignored */
- << llvm::to_underlying(CalleeTarget) << llvm::to_underlying(CallerTarget);
+ << CalleeTarget << CallerTarget;
// This could be an implicit constructor for which we could not infer the
// target due to a collsion. Diagnose that case.
@@ -15528,8 +15528,7 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
DefaultedFunctionKind DFK = getDefaultedFunctionKind(DeletedFD);
if (DFK.isSpecialMember()) {
Diag(OpLoc, diag::err_ovl_deleted_special_oper)
- << Args[0]->getType()
- << llvm::to_underlying(DFK.asSpecialMember());
+ << Args[0]->getType() << DFK.asSpecialMember();
} else {
assert(DFK.isComparison());
Diag(OpLoc, diag::err_ovl_deleted_comparison)
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index e207251..9f517b2 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -4318,7 +4318,7 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
// Exceptions aren't allowed in CUDA device code.
if (getLangOpts().CUDA)
CUDA().DiagIfDeviceCode(TryLoc, diag::err_cuda_device_exceptions)
- << "try" << llvm::to_underlying(CUDA().CurrentTarget());
+ << "try" << CUDA().CurrentTarget();
if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) << "try";
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 633ce2b..6a258ca 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3911,7 +3911,7 @@ TypeResult Sema::ActOnTagTemplateIdType(TagUseKind TUK,
// resolves to an alias template specialization, the
// elaborated-type-specifier is ill-formed.
Diag(TemplateLoc, diag::err_tag_reference_non_tag)
- << TAT << NTK_TypeAliasTemplate << llvm::to_underlying(TagKind);
+ << TAT << NTK_TypeAliasTemplate << TagKind;
Diag(TAT->getLocation(), diag::note_declared_at);
}
@@ -9779,8 +9779,7 @@ DeclResult Sema::ActOnExplicitInstantiation(
if (!ClassTemplate) {
NonTagKind NTK = getNonTagTypeDeclKind(TD, Kind);
- Diag(TemplateNameLoc, diag::err_tag_reference_non_tag)
- << TD << NTK << llvm::to_underlying(Kind);
+ Diag(TemplateNameLoc, diag::err_tag_reference_non_tag) << TD << NTK << Kind;
Diag(TD->getLocation(), diag::note_previous_use);
return true;
}
@@ -10643,8 +10642,7 @@ TypeResult Sema::ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
if (TUK == TagUseKind::Declaration || TUK == TagUseKind::Definition) {
Diag(NameLoc, diag::err_dependent_tag_decl)
- << (TUK == TagUseKind::Definition) << llvm::to_underlying(Kind)
- << SS.getRange();
+ << (TUK == TagUseKind::Definition) << Kind << SS.getRange();
return true;
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 0e81804..390ff3e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1124,7 +1124,7 @@ void Sema::PrintInstantiationStack(InstantiationContextDiagFuncRef DiagFunc) {
DiagFunc(Active->PointOfInstantiation,
PDiag(diag::note_in_declaration_of_implicit_special_member)
<< cast<CXXRecordDecl>(Active->Entity)
- << llvm::to_underlying(Active->SpecialMember));
+ << Active->SpecialMember);
break;
case CodeSynthesisContext::DeclaringImplicitEqualityComparison:
@@ -1143,8 +1143,7 @@ void Sema::PrintInstantiationStack(InstantiationContextDiagFuncRef DiagFunc) {
auto *MD = cast<CXXMethodDecl>(FD);
DiagFunc(Active->PointOfInstantiation,
PDiag(diag::note_member_synthesized_at)
- << MD->isExplicitlyDefaulted()
- << llvm::to_underlying(DFK.asSpecialMember())
+ << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
<< Context.getTagDeclType(MD->getParent()));
} else if (DFK.isComparison()) {
QualType RecordType = FD->getParamDecl(0)
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 76c055d..08b3a42 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2211,8 +2211,8 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
if (!PrevClassTemplate && QualifierLoc) {
SemaRef.Diag(Pattern->getLocation(), diag::err_not_tag_in_scope)
- << llvm::to_underlying(D->getTemplatedDecl()->getTagKind())
- << Pattern->getDeclName() << DC << QualifierLoc.getSourceRange();
+ << D->getTemplatedDecl()->getTagKind() << Pattern->getDeclName() << DC
+ << QualifierLoc.getSourceRange();
return nullptr;
}
}
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6e7ee8b..444b8d9 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2298,7 +2298,7 @@ QualType Sema::BuildArrayType(QualType T, ArraySizeModifier ASM,
(ASM != ArraySizeModifier::Normal || Quals != 0)) {
Diag(Loc, getLangOpts().CPlusPlus ? diag::err_c99_array_usage_cxx
: diag::ext_c99_array_usage)
- << llvm::to_underlying(ASM);
+ << ASM;
}
// OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index b6af919..3bcbe0f 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -1223,14 +1223,13 @@ public:
NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
- << SomeDecl << NTK << llvm::to_underlying(Kind);
+ << SomeDecl << NTK << Kind;
SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
break;
}
default:
SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
- << llvm::to_underlying(Kind) << Id << DC
- << QualifierLoc.getSourceRange();
+ << Kind << Id << DC << QualifierLoc.getSourceRange();
break;
}
return QualType();
@@ -7510,8 +7509,7 @@ TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
diag::err_tag_reference_non_tag)
<< TAT << Sema::NTK_TypeAliasTemplate
- << llvm::to_underlying(
- ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()));
+ << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
}
}