@@ -872,6 +872,13 @@ class KernelObjVisitor {
872
872
(handlers.leaveUnion (Owner, Parent), 0 )...};
873
873
}
874
874
875
+ // Handle empty base case.
876
+ template <typename ParentTy>
877
+ void VisitUnion (const CXXRecordDecl *Owner, ParentTy &Parent,
878
+ const CXXRecordDecl *Wrapper) {}
879
+
880
+ // Add overloads including the base case when
881
+ // sizeof...(FilteredHandlers) > 0.
875
882
template <typename ... FilteredHandlers, typename ParentTy,
876
883
typename CurHandler, typename ... Handlers>
877
884
std::enable_if_t <!CurHandler::VisitUnionBody>
@@ -894,6 +901,8 @@ class KernelObjVisitor {
894
901
filtered_handlers..., cur_handler, Owner, Parent, Wrapper, handlers...);
895
902
}
896
903
904
+ // Add overloads without having filtered-handlers
905
+ // to handle leading-empty argument packs.
897
906
template <typename ParentTy, typename CurHandler, typename ... Handlers>
898
907
std::enable_if_t <!CurHandler::VisitUnionBody>
899
908
VisitUnion (const CXXRecordDecl *Owner, ParentTy &Parent,
@@ -1275,6 +1284,14 @@ class SyclKernelUnionChecker : public SyclKernelFieldHandler {
1275
1284
bool isValid () { return !IsInvalid; }
1276
1285
static constexpr const bool VisitUnionBody = true ;
1277
1286
1287
+ bool checkType (SourceLocation Loc, QualType Ty) {
1288
+ if (UnionCount) {
1289
+ IsInvalid = true ;
1290
+ Diag.Report (Loc, diag::err_bad_union_kernel_param_members) << Ty;
1291
+ }
1292
+ return isValid ();
1293
+ }
1294
+
1278
1295
bool enterUnion (const CXXRecordDecl *RD, FieldDecl *FD) {
1279
1296
++UnionCount;
1280
1297
return true ;
@@ -1286,60 +1303,30 @@ class SyclKernelUnionChecker : public SyclKernelFieldHandler {
1286
1303
}
1287
1304
1288
1305
bool handleSyclAccessorType (FieldDecl *FD, QualType FieldTy) final {
1289
- if (UnionCount) {
1290
- IsInvalid = true ;
1291
- Diag.Report (FD->getLocation (), diag::err_bad_union_kernel_param_members)
1292
- << FieldTy;
1293
- }
1294
- return isValid ();
1306
+ return checkType (FD->getLocation (), FieldTy);
1295
1307
}
1296
1308
1297
1309
bool handleSyclAccessorType (const CXXBaseSpecifier &BS,
1298
1310
QualType FieldTy) final {
1299
- if (UnionCount) {
1300
- IsInvalid = true ;
1301
- Diag.Report (BS.getBeginLoc (), diag::err_bad_union_kernel_param_members)
1302
- << FieldTy;
1303
- }
1304
- return isValid ();
1311
+ return checkType (BS.getBeginLoc (), FieldTy);
1305
1312
}
1306
1313
1307
1314
bool handleSyclSamplerType (FieldDecl *FD, QualType FieldTy) final {
1308
- if (UnionCount) {
1309
- IsInvalid = true ;
1310
- Diag.Report (FD->getLocation (), diag::err_bad_union_kernel_param_members)
1311
- << FieldTy;
1312
- }
1313
- return isValid ();
1315
+ return checkType (FD->getLocation (), FieldTy);
1314
1316
}
1315
1317
1316
1318
bool handleSyclSamplerType (const CXXBaseSpecifier &BS,
1317
1319
QualType FieldTy) final {
1318
- if (UnionCount) {
1319
- IsInvalid = true ;
1320
- Diag.Report (BS.getBeginLoc (), diag::err_bad_union_kernel_param_members)
1321
- << FieldTy;
1322
- }
1323
- return isValid ();
1320
+ return checkType (BS.getBeginLoc (), FieldTy);
1324
1321
}
1325
1322
1326
1323
bool handleSyclStreamType (FieldDecl *FD, QualType FieldTy) final {
1327
- if (UnionCount) {
1328
- IsInvalid = true ;
1329
- Diag.Report (FD->getLocation (), diag::err_bad_union_kernel_param_members)
1330
- << FieldTy;
1331
- }
1332
- return isValid ();
1324
+ return checkType (FD->getLocation (), FieldTy);
1333
1325
}
1334
1326
1335
1327
bool handleSyclStreamType (const CXXBaseSpecifier &BS,
1336
1328
QualType FieldTy) final {
1337
- if (UnionCount) {
1338
- IsInvalid = true ;
1339
- Diag.Report (BS.getBeginLoc (), diag::err_bad_union_kernel_param_members)
1340
- << FieldTy;
1341
- }
1342
- return isValid ();
1329
+ return checkType (BS.getBeginLoc (), FieldTy);
1343
1330
}
1344
1331
};
1345
1332
0 commit comments