aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCUDA.cpp
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/SemaCUDA.cpp
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/SemaCUDA.cpp')
-rw-r--r--clang/lib/Sema/SemaCUDA.cpp17
1 files changed, 7 insertions, 10 deletions
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);
}
}