24#include "llvm/ADT/SmallPtrSet.h"
47 auto *RD = dyn_cast<CXXRecordDecl>(
CurContext);
54 if (!RD || !RD->getIdentifier() || !RD->getDescribedClassTemplate() ||
58 auto *ND = dyn_cast<NamespaceDecl>(RD->getDeclContext());
62 bool IsInStd = ND->isStdNamespace();
67 if (!II || !(II->
isStr(
"__debug") || II->
isStr(
"__profile")) ||
68 !ND->isInStdNamespace())
76 return llvm::StringSwitch<bool>(RD->getIdentifier()->getName())
78 .Case(
"pair", IsInStd)
79 .Case(
"priority_queue", IsInStd)
80 .Case(
"stack", IsInStd)
81 .Case(
"queue", IsInStd)
103 llvm::APSInt
Value{1};
125 if (T->isArrayType())
126 T =
Context.getArrayDecayedType(T);
127 else if (T->isFunctionType())
144 if (RT->isRValueReferenceType()) {
148 Diag(Range.getBegin(), diag::err_rref_in_exception_spec)
161 unsigned DiagID = diag::err_incomplete_in_exception_spec;
162 bool ReturnValueOnError =
true;
164 DiagID = diag::ext_incomplete_in_exception_spec;
165 ReturnValueOnError =
false;
168 !(RD && RD->isBeingDefined()) &&
170 return ReturnValueOnError;
174 Diag(Range.getBegin(), diag::err_wasm_reftype_exception_spec);
181 Diag(Range.getBegin(), diag::err_sizeless_in_exception_spec)
182 << (Kind == 2 ? 1 : 0) << PointeeT << Range;
196 T = PT->getPointeeType();
198 T = PT->getPointeeType();
212 Diag(Loc, diag::err_exception_spec_not_parsed);
236 Diag(Loc, diag::err_exception_spec_not_parsed);
248 Listener->ResolvedExceptionSpec(FD);
251 Context.adjustExceptionSpec(Redecl, ESI);
266 Sema &S,
const PartialDiagnostic &DiagID,
const PartialDiagnostic &NoteID,
267 const FunctionProtoType *Old, SourceLocation OldLoc,
268 const FunctionProtoType *
New, SourceLocation NewLoc,
269 bool *MissingExceptionSpecification =
nullptr,
270 bool *MissingEmptyExceptionSpecification =
nullptr,
271 bool AllowNoexceptAllMatchWithNoSpec =
false,
bool IsOperatorNew =
false);
277 Decl->getDeclName().getCXXOverloadedOperator() != OO_Delete &&
278 Decl->getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
286 if (!
Decl->getTypeSourceInfo())
301 bool IsOperatorNew = OO == OO_New || OO == OO_Array_New;
302 bool MissingExceptionSpecification =
false;
303 bool MissingEmptyExceptionSpecification =
false;
305 unsigned DiagID = diag::err_mismatched_exception_spec;
306 bool ReturnValueOnError =
true;
308 DiagID = diag::ext_mismatched_exception_spec;
309 ReturnValueOnError =
false;
323 *
this,
PDiag(DiagID),
PDiag(diag::note_previous_declaration),
326 &MissingExceptionSpecification, &MissingEmptyExceptionSpecification,
327 true, IsOperatorNew)) {
334 Diag(
New->getLocation(), diag::ext_implicit_exception_spec_mismatch)
344 if (!MissingExceptionSpecification)
345 return ReturnValueOnError;
357 if (MissingEmptyExceptionSpecification &&
363 NewProto->getReturnType(), NewProto->getParamTypes(),
374 ESI.Exceptions = OldProto->exceptions();
385 New->setInvalidDecl();
390 NewProto->getReturnType(), NewProto->getParamTypes(),
391 NewProto->getExtProtoInfo().withExceptionSpec(ESI)));
395 DiagID = diag::ext_missing_exception_specification;
396 ReturnValueOnError =
false;
397 }
else if (
New->isReplaceableGlobalAllocationFunction() &&
401 DiagID = diag::ext_missing_exception_specification;
402 ReturnValueOnError =
false;
410 DiagID = diag::ext_missing_exception_specification;
411 ReturnValueOnError =
false;
413 DiagID = diag::err_missing_exception_specification;
414 ReturnValueOnError =
true;
419 llvm::raw_svector_ostream
OS(ExceptionSpecString);
420 switch (OldProto->getExceptionSpecType()) {
427 bool OnFirstException =
true;
428 for (
const auto &E : OldProto->exceptions()) {
429 if (OnFirstException)
430 OnFirstException =
false;
448 assert(OldProto->getNoexceptExpr() !=
nullptr &&
"Expected non-null Expr");
453 OS <<
"__attribute__((nothrow))";
460 llvm_unreachable(
"This spec type is compatible with none.");
469 if (!FTLoc.getTypePtr()->hasTrailingReturn())
474 Diag(
New->getLocation(), DiagID)
477 Diag(
New->getLocation(), DiagID)
485 return ReturnValueOnError;
494 unsigned DiagID = diag::err_mismatched_exception_spec;
496 DiagID = diag::ext_mismatched_exception_spec;
498 *
this,
PDiag(DiagID),
PDiag(diag::note_previous_declaration),
499 Old, OldLoc,
New, NewLoc);
517 bool *MissingExceptionSpecification,
518 bool *MissingEmptyExceptionSpecification,
519 bool AllowNoexceptAllMatchWithNoSpec,
bool IsOperatorNew) {
520 if (MissingExceptionSpecification)
521 *MissingExceptionSpecification =
false;
523 if (MissingEmptyExceptionSpecification)
524 *MissingEmptyExceptionSpecification =
false;
557 "Shouldn't see unknown exception specifications here");
571 if (!AllowNoexceptAllMatchWithNoSpec &&
584 llvm::FoldingSetNodeID OldFSN, NewFSN;
586 New->getNoexceptExpr()->Profile(NewFSN, S.
Context,
true);
587 if (OldFSN == NewFSN)
601 for (
const auto &I :
New->exceptions()) {
603 if (OldTypes.count(TypePtr))
604 NewTypes.insert(TypePtr);
611 if (
Success && OldTypes.size() == NewTypes.size())
618 if (S.
getLangOpts().CPlusPlus11 && IsOperatorNew) {
621 WithExceptions =
New;
623 WithExceptions = Old;
630 if (Name && Name->
getName() ==
"bad_alloc") {
632 if (ExRecord->isInStdNamespace()) {
642 if (MissingExceptionSpecification && OldEST !=
EST_None &&
646 *MissingExceptionSpecification =
true;
648 if (MissingEmptyExceptionSpecification && OldCanThrow ==
CT_Cannot) {
652 *MissingEmptyExceptionSpecification =
true;
658 S.
Diag(NewLoc, DiagID);
660 S.
Diag(OldLoc, NoteID);
687 if (
Context.hasSameUnqualifiedType(ExceptionType, HandlerType))
720 ExceptionType =
Context.getUnqualifiedArrayType(
752 llvm_unreachable(
"access check dependent for unprivileged context");
754 llvm_unreachable(
"access check delayed in non-declaration");
756 llvm_unreachable(
"unexpected access check result");
788 "Shouldn't see unknown exception specifications here");
805 SkipSupersetFirstParameter, SuperLoc, Subset,
806 SkipSubsetFirstParameter, SubLoc);
812 Diag(SubLoc, NoThrowDiagID);
814 Diag(SuperLoc, NoteID);
822 Diag(SubLoc, DiagID);
824 Diag(SuperLoc, NoteID);
829 "Exception spec subset: non-dynamic case slipped through.");
834 SubI = RefTy->getPointeeType();
837 bool Contained =
false;
851 Diag(SubLoc, DiagID);
853 Diag(SuperLoc, NoteID);
859 SkipSupersetFirstParameter, SuperLoc, Subset,
860 SkipSupersetFirstParameter, SubLoc);
884 auto RetDiag = DiagID;
887 *
this, RetDiag,
PDiag(),
888 Target->getReturnType(), TargetLoc, Source->getReturnType(),
894 assert((
Target->getNumParams() - (
unsigned)SkipTargetFirstParameter) ==
895 (Source->getNumParams() - (
unsigned)SkipSourceFirstParameter) &&
896 "Functions have different argument counts.");
897 for (
unsigned i = 0, E =
Target->getNumParams(); i != E; ++i) {
898 auto ParamDiag = DiagID;
901 *
this, ParamDiag,
PDiag(),
902 Target->getParamType(i + (SkipTargetFirstParameter ? 1 : 0)),
903 TargetLoc, Source->getParamType(SkipSourceFirstParameter ? 1 : 0),
922 unsigned DiagID = diag::err_incompatible_exception_specs;
923 unsigned NestedDiagID = diag::err_deep_exception_specs_differ;
928 DiagID = diag::warn_incompatible_exception_specs;
929 NestedDiagID = diag::warn_deep_exception_specs_differ;
973 unsigned DiagID = diag::err_override_exception_spec;
975 DiagID = diag::ext_override_exception_spec;
977 PDiag(DiagID),
PDiag(diag::err_deep_exception_specs_differ),
978 PDiag(diag::note_overridden_virtual_function),
979 PDiag(diag::ext_override_exception_spec),
983 New->hasCXXExplicitFunctionObjectParameter(),
New->getLocation());
1002 if (isa_and_nonnull<FunctionDecl>(D) && D->
hasAttr<NoThrowAttr>())
1008 if (S.
getLangOpts().CPlusPlus17 && isa_and_nonnull<CallExpr>(E)) {
1011 if (T->isSpecificPlaceholderType(BuiltinType::BoundMember)) {
1017 if (
auto *Op = dyn_cast<BinaryOperator>(E)) {
1018 assert(Op->getOpcode() == BO_PtrMemD || Op->getOpcode() == BO_PtrMemI);
1019 T = Op->getRHS()->getType()
1025 }
else if (
const ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D))
1065 if (
auto *Dtor = RD->getDestructor()) {
1073 if (
auto *DD = dyn_cast<DecompositionDecl>(VD))
1074 for (
auto *B : DD->flat_bindings())
1075 if (
auto *HD = B->getHoldingVar())
1118 case Expr::ConstantExprClass:
1121 case Expr::CXXThrowExprClass:
1125 case Expr::CXXDynamicCastExprClass: {
1130 if (CE->getType()->isVariablyModifiedType())
1138 case Expr::CXXTypeidExprClass:
1147 case Expr::CallExprClass:
1148 case Expr::CXXMemberCallExprClass:
1149 case Expr::CXXOperatorCallExprClass:
1150 case Expr::UserDefinedLiteralClass: {
1164 case Expr::CXXConstructExprClass:
1165 case Expr::CXXTemporaryObjectExprClass: {
1168 if (CE->getType()->isVariablyModifiedType())
1176 case Expr::CXXInheritedCtorInitExprClass: {
1181 case Expr::LambdaExprClass: {
1187 Cap != CapEnd; ++Cap)
1192 case Expr::CXXNewExprClass: {
1195 if (NE->isTypeDependent())
1204 case Expr::CXXDeleteExprClass: {
1207 QualType DTy = DE->getDestroyedType();
1216 const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
1233 case Expr::CXXBindTemporaryExprClass: {
1237 canCalleeThrow(*
this, BTE, BTE->getTemporary()->getDestructor());
1243 case Expr::PseudoObjectExprClass: {
1246 for (
const Expr *E : POE->semantics()) {
1254 case Stmt::SYCLKernelCallStmtClass: {
1258 SKCS->getOutlinedFunctionDecl()->getBody());
1263 case Stmt::UnresolvedSYCLKernelCallStmtClass:
1268 case Expr::ObjCMessageExprClass:
1269 case Expr::ObjCPropertyRefExprClass:
1270 case Expr::ObjCSubscriptRefExprClass:
1276 case Expr::ObjCArrayLiteralClass:
1277 case Expr::ObjCDictionaryLiteralClass:
1278 case Expr::ObjCBoxedExprClass:
1283 case Expr::CoawaitExprClass:
1284 case Expr::ConditionalOperatorClass:
1285 case Expr::CoyieldExprClass:
1286 case Expr::CXXRewrittenBinaryOperatorClass:
1287 case Expr::CXXStdInitializerListExprClass:
1288 case Expr::DesignatedInitExprClass:
1289 case Expr::DesignatedInitUpdateExprClass:
1290 case Expr::ExprWithCleanupsClass:
1291 case Expr::ExtVectorElementExprClass:
1292 case Expr::MatrixElementExprClass:
1293 case Expr::InitListExprClass:
1294 case Expr::ArrayInitLoopExprClass:
1295 case Expr::MemberExprClass:
1296 case Expr::ObjCIsaExprClass:
1297 case Expr::ObjCIvarRefExprClass:
1298 case Expr::ParenExprClass:
1299 case Expr::ParenListExprClass:
1300 case Expr::ShuffleVectorExprClass:
1301 case Expr::StmtExprClass:
1302 case Expr::ConvertVectorExprClass:
1303 case Expr::VAArgExprClass:
1304 case Expr::CXXParenListInitExprClass:
1307 case Expr::CompoundLiteralExprClass:
1308 case Expr::CXXConstCastExprClass:
1309 case Expr::CXXAddrspaceCastExprClass:
1310 case Expr::CXXReinterpretCastExprClass:
1311 case Expr::BuiltinBitCastExprClass:
1318 case Expr::ArraySubscriptExprClass:
1319 case Expr::MatrixSubscriptExprClass:
1320 case Expr::MatrixSingleSubscriptExprClass:
1321 case Expr::ArraySectionExprClass:
1322 case Expr::OMPArrayShapingExprClass:
1323 case Expr::OMPIteratorExprClass:
1324 case Expr::BinaryOperatorClass:
1325 case Expr::DependentCoawaitExprClass:
1326 case Expr::CompoundAssignOperatorClass:
1327 case Expr::CStyleCastExprClass:
1328 case Expr::CXXStaticCastExprClass:
1329 case Expr::CXXFunctionalCastExprClass:
1330 case Expr::ImplicitCastExprClass:
1331 case Expr::MaterializeTemporaryExprClass:
1332 case Expr::UnaryOperatorClass: {
1334 if (
auto *CE = dyn_cast<CastExpr>(S))
1335 if (CE->getType()->isVariablyModifiedType())
1342 case Expr::CXXDefaultArgExprClass:
1345 case Expr::CXXDefaultInitExprClass:
1348 case Expr::ChooseExprClass: {
1350 if (CE->isTypeDependent() || CE->isValueDependent())
1352 return canThrow(CE->getChosenSubExpr());
1355 case Expr::GenericSelectionExprClass:
1361 case Expr::CXXDependentScopeMemberExprClass:
1362 case Expr::CXXUnresolvedConstructExprClass:
1363 case Expr::DependentScopeDeclRefExprClass:
1364 case Expr::CXXFoldExprClass:
1365 case Expr::RecoveryExprClass:
1368 case Expr::AsTypeExprClass:
1369 case Expr::BinaryConditionalOperatorClass:
1370 case Expr::BlockExprClass:
1371 case Expr::CUDAKernelCallExprClass:
1372 case Expr::DeclRefExprClass:
1373 case Expr::ObjCBridgedCastExprClass:
1374 case Expr::ObjCIndirectCopyRestoreExprClass:
1375 case Expr::ObjCProtocolExprClass:
1376 case Expr::ObjCSelectorExprClass:
1377 case Expr::ObjCAvailabilityCheckExprClass:
1378 case Expr::OffsetOfExprClass:
1379 case Expr::PackExpansionExprClass:
1380 case Expr::SubstNonTypeTemplateParmExprClass:
1381 case Expr::SubstNonTypeTemplateParmPackExprClass:
1382 case Expr::FunctionParmPackExprClass:
1383 case Expr::UnaryExprOrTypeTraitExprClass:
1384 case Expr::UnresolvedLookupExprClass:
1385 case Expr::UnresolvedMemberExprClass:
1389 case Expr::AddrLabelExprClass:
1390 case Expr::ArrayTypeTraitExprClass:
1391 case Expr::AtomicExprClass:
1392 case Expr::TypeTraitExprClass:
1393 case Expr::CXXBoolLiteralExprClass:
1394 case Expr::CXXNoexceptExprClass:
1395 case Expr::CXXNullPtrLiteralExprClass:
1396 case Expr::CXXPseudoDestructorExprClass:
1397 case Expr::CXXReflectExprClass:
1398 case Expr::CXXScalarValueInitExprClass:
1399 case Expr::CXXThisExprClass:
1400 case Expr::CXXUuidofExprClass:
1401 case Expr::CharacterLiteralClass:
1402 case Expr::ExpressionTraitExprClass:
1403 case Expr::FloatingLiteralClass:
1404 case Expr::GNUNullExprClass:
1405 case Expr::ImaginaryLiteralClass:
1406 case Expr::ImplicitValueInitExprClass:
1407 case Expr::IntegerLiteralClass:
1408 case Expr::FixedPointLiteralClass:
1409 case Expr::ArrayInitIndexExprClass:
1410 case Expr::NoInitExprClass:
1411 case Expr::ObjCEncodeExprClass:
1412 case Expr::ObjCStringLiteralClass:
1413 case Expr::ObjCBoolLiteralExprClass:
1414 case Expr::OpaqueValueExprClass:
1415 case Expr::PredefinedExprClass:
1416 case Expr::SizeOfPackExprClass:
1417 case Expr::PackIndexingExprClass:
1418 case Expr::StringLiteralClass:
1419 case Expr::SourceLocExprClass:
1420 case Expr::EmbedExprClass:
1421 case Expr::ConceptSpecializationExprClass:
1422 case Expr::RequiresExprClass:
1423 case Expr::HLSLOutArgExprClass:
1424 case Stmt::OpenACCEnterDataConstructClass:
1425 case Stmt::OpenACCExitDataConstructClass:
1426 case Stmt::OpenACCWaitConstructClass:
1427 case Stmt::OpenACCCacheConstructClass:
1428 case Stmt::OpenACCInitConstructClass:
1429 case Stmt::OpenACCShutdownConstructClass:
1430 case Stmt::OpenACCSetConstructClass:
1431 case Stmt::OpenACCUpdateConstructClass:
1435 case Expr::MSPropertyRefExprClass:
1436 case Expr::MSPropertySubscriptExprClass:
1437 llvm_unreachable(
"Invalid class for expression");
1440 case Stmt::OpenACCComputeConstructClass:
1441 case Stmt::OpenACCLoopConstructClass:
1442 case Stmt::OpenACCCombinedConstructClass:
1443 case Stmt::OpenACCDataConstructClass:
1444 case Stmt::OpenACCHostDataConstructClass:
1445 case Stmt::OpenACCAtomicConstructClass:
1446 case Stmt::AttributedStmtClass:
1447 case Stmt::BreakStmtClass:
1448 case Stmt::CapturedStmtClass:
1449 case Stmt::CaseStmtClass:
1450 case Stmt::CompoundStmtClass:
1451 case Stmt::ContinueStmtClass:
1452 case Stmt::CoreturnStmtClass:
1453 case Stmt::CoroutineBodyStmtClass:
1454 case Stmt::CXXCatchStmtClass:
1455 case Stmt::CXXForRangeStmtClass:
1456 case Stmt::DefaultStmtClass:
1457 case Stmt::DoStmtClass:
1458 case Stmt::ForStmtClass:
1459 case Stmt::GCCAsmStmtClass:
1460 case Stmt::GotoStmtClass:
1461 case Stmt::IndirectGotoStmtClass:
1462 case Stmt::LabelStmtClass:
1463 case Stmt::MSAsmStmtClass:
1464 case Stmt::MSDependentExistsStmtClass:
1465 case Stmt::NullStmtClass:
1466 case Stmt::ObjCAtCatchStmtClass:
1467 case Stmt::ObjCAtFinallyStmtClass:
1468 case Stmt::ObjCAtSynchronizedStmtClass:
1469 case Stmt::ObjCAutoreleasePoolStmtClass:
1470 case Stmt::ObjCForCollectionStmtClass:
1471 case Stmt::OMPAtomicDirectiveClass:
1472 case Stmt::OMPAssumeDirectiveClass:
1473 case Stmt::OMPBarrierDirectiveClass:
1474 case Stmt::OMPCancelDirectiveClass:
1475 case Stmt::OMPCancellationPointDirectiveClass:
1476 case Stmt::OMPCriticalDirectiveClass:
1477 case Stmt::OMPDistributeDirectiveClass:
1478 case Stmt::OMPDistributeParallelForDirectiveClass:
1479 case Stmt::OMPDistributeParallelForSimdDirectiveClass:
1480 case Stmt::OMPDistributeSimdDirectiveClass:
1481 case Stmt::OMPFlushDirectiveClass:
1482 case Stmt::OMPDepobjDirectiveClass:
1483 case Stmt::OMPScanDirectiveClass:
1484 case Stmt::OMPForDirectiveClass:
1485 case Stmt::OMPForSimdDirectiveClass:
1486 case Stmt::OMPMasterDirectiveClass:
1487 case Stmt::OMPMasterTaskLoopDirectiveClass:
1488 case Stmt::OMPMaskedTaskLoopDirectiveClass:
1489 case Stmt::OMPMasterTaskLoopSimdDirectiveClass:
1490 case Stmt::OMPMaskedTaskLoopSimdDirectiveClass:
1491 case Stmt::OMPOrderedDirectiveClass:
1492 case Stmt::OMPCanonicalLoopClass:
1493 case Stmt::OMPParallelDirectiveClass:
1494 case Stmt::OMPParallelForDirectiveClass:
1495 case Stmt::OMPParallelForSimdDirectiveClass:
1496 case Stmt::OMPParallelMasterDirectiveClass:
1497 case Stmt::OMPParallelMaskedDirectiveClass:
1498 case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
1499 case Stmt::OMPParallelMaskedTaskLoopDirectiveClass:
1500 case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
1501 case Stmt::OMPParallelMaskedTaskLoopSimdDirectiveClass:
1502 case Stmt::OMPParallelSectionsDirectiveClass:
1503 case Stmt::OMPSectionDirectiveClass:
1504 case Stmt::OMPSectionsDirectiveClass:
1505 case Stmt::OMPSimdDirectiveClass:
1506 case Stmt::OMPTileDirectiveClass:
1507 case Stmt::OMPStripeDirectiveClass:
1508 case Stmt::OMPUnrollDirectiveClass:
1509 case Stmt::OMPReverseDirectiveClass:
1510 case Stmt::OMPInterchangeDirectiveClass:
1511 case Stmt::OMPFuseDirectiveClass:
1512 case Stmt::OMPSingleDirectiveClass:
1513 case Stmt::OMPTargetDataDirectiveClass:
1514 case Stmt::OMPTargetDirectiveClass:
1515 case Stmt::OMPTargetEnterDataDirectiveClass:
1516 case Stmt::OMPTargetExitDataDirectiveClass:
1517 case Stmt::OMPTargetParallelDirectiveClass:
1518 case Stmt::OMPTargetParallelForDirectiveClass:
1519 case Stmt::OMPTargetParallelForSimdDirectiveClass:
1520 case Stmt::OMPTargetSimdDirectiveClass:
1521 case Stmt::OMPTargetTeamsDirectiveClass:
1522 case Stmt::OMPTargetTeamsDistributeDirectiveClass:
1523 case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
1524 case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
1525 case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
1526 case Stmt::OMPTargetUpdateDirectiveClass:
1527 case Stmt::OMPScopeDirectiveClass:
1528 case Stmt::OMPTaskDirectiveClass:
1529 case Stmt::OMPTaskgroupDirectiveClass:
1530 case Stmt::OMPTaskLoopDirectiveClass:
1531 case Stmt::OMPTaskLoopSimdDirectiveClass:
1532 case Stmt::OMPTaskwaitDirectiveClass:
1533 case Stmt::OMPTaskyieldDirectiveClass:
1534 case Stmt::OMPErrorDirectiveClass:
1535 case Stmt::OMPTeamsDirectiveClass:
1536 case Stmt::OMPTeamsDistributeDirectiveClass:
1537 case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
1538 case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
1539 case Stmt::OMPTeamsDistributeSimdDirectiveClass:
1540 case Stmt::OMPInteropDirectiveClass:
1541 case Stmt::OMPDispatchDirectiveClass:
1542 case Stmt::OMPMaskedDirectiveClass:
1543 case Stmt::OMPMetaDirectiveClass:
1544 case Stmt::OMPGenericLoopDirectiveClass:
1545 case Stmt::OMPTeamsGenericLoopDirectiveClass:
1546 case Stmt::OMPTargetTeamsGenericLoopDirectiveClass:
1547 case Stmt::OMPParallelGenericLoopDirectiveClass:
1548 case Stmt::OMPTargetParallelGenericLoopDirectiveClass:
1549 case Stmt::ReturnStmtClass:
1550 case Stmt::SEHExceptStmtClass:
1551 case Stmt::SEHFinallyStmtClass:
1552 case Stmt::SEHLeaveStmtClass:
1553 case Stmt::SEHTryStmtClass:
1554 case Stmt::SwitchStmtClass:
1555 case Stmt::WhileStmtClass:
1556 case Stmt::DeferStmtClass:
1559 case Stmt::DeclStmtClass: {
1562 if (
auto *VD = dyn_cast<VarDecl>(D))
1566 if (
auto *TND = dyn_cast<TypedefNameDecl>(D))
1567 if (TND->getUnderlyingType()->isVariablyModifiedType())
1569 if (
auto *VD = dyn_cast<ValueDecl>(D))
1570 if (VD->getType()->isVariablyModifiedType())
1576 case Stmt::IfStmtClass: {
1579 if (
const Stmt *
Init = IS->getInit())
1581 if (
const Stmt *CondDS = IS->getConditionVariableDeclStmt())
1587 if (std::optional<const Stmt *> Case = IS->getNondiscardedCase(
Context))
1601 case Stmt::CXXTryStmtClass: {
1605 const CXXCatchStmt *FinalHandler = TS->getHandler(TS->getNumHandlers() - 1);
1611 case Stmt::ObjCAtThrowStmtClass:
1614 case Stmt::ObjCAtTryStmtClass: {
1620 if (
const Stmt *Finally = TS->getFinallyStmt())
1622 for (
unsigned I = TS->getNumCatchStmts(); I != 0; --I) {
1634 case Stmt::SYCLUniqueStableNameExprClass:
1636 case Stmt::OpenACCAsteriskSizeExprClass:
1639 llvm_unreachable(
"Invalid class for statement");
1641 llvm_unreachable(
"Bogus StmtClass");
Defines the Diagnostic-related interfaces.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::Preprocessor interface.
Defines the SourceManager interface.
Defines the Objective-C statement AST node classes.
Expr * getExpr()
Get 'expr' part of the associated expression/statement.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
static QualType getPointeeType(const MemRegion *R)
Defines the clang::TypeLoc interface and its subclasses.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
bool isAmbiguous(CanQualType BaseType) const
Determine whether the path from the most-derived type to the given base type is ambiguous (i....
A boolean literal, per ([C++ lex.bool] Boolean literals).
CXXCatchStmt - This represents a C++ catch block.
Stmt * getHandlerBlock() const
VarDecl * getExceptionDecl() const
Represents a C++ destructor within a class.
bool isCalledByDelete(const FunctionDecl *OpDel=nullptr) const
Will this destructor ever be called when considering which deallocation function is associated with t...
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isTypeOperand() const
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
bool hasNullCheck() const
Whether this is of a form like "typeid(*ptr)" that can throw a std::bad_typeid if a pointer is a null...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
CastKind getCastKind() const
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Information about one declarator, including the parsed type information and the identifier.
SourceLocation getBeginLoc() const LLVM_READONLY
const IdentifierInfo * getIdentifier() const
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
bool hasCXXExplicitFunctionObjectParameter() const
bool isExternC() const
Determines whether this function is a function with external, C linkage.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Represents a prototype with parameter type info, e.g.
bool hasDependentExceptionSpec() const
Return whether this function has a dependent exception spec.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumExceptions() const
Return the number of types in the exception specification.
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
ArrayRef< QualType > exceptions() const
exception_iterator exception_begin() const
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument for this lambda expression.
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
A pointer to member type per C++ 8.3.3 - Pointers to members.
Represents Objective-C's @catch statement.
unsigned getDiagID() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
bool isConstQualified() const
Determine whether this type is const-qualified.
The collection of all-type qualifiers we support.
bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const
Determines if these qualifiers compatibly include another set.
Base for LValueReferenceType and RValueReferenceType.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Sema - This implements semantic analysis and AST building for C.
bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range)
CheckSpecifiedExceptionType - Check if the given type is valid in an exception specification.
void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD)
Evaluate the implicit exception specification for a defaulted special member function.
void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, FunctionDecl *Function)
Preprocessor & getPreprocessor() const
bool IsQualificationConversion(QualType FromType, QualType ToType, bool CStyle, bool &ObjCLifetimeConversion)
IsQualificationConversion - Determines whether the conversion from an rvalue of type FromType to ToTy...
ASTContext & getASTContext() const
SmallVector< std::pair< FunctionDecl *, FunctionDecl * >, 2 > DelayedEquivalentExceptionSpecChecks
All the function redeclarations seen during a class definition that had their exception spec checks d...
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, llvm::APSInt &Value, CCEKind CCE)
bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, const PartialDiagnostic &NoteID, const FunctionProtoType *Target, bool SkipTargetFirstParameter, SourceLocation TargetLoc, const FunctionProtoType *Source, bool SkipSourceFirstParameter, SourceLocation SourceLoc)
CheckParamExceptionSpec - Check if the parameter and return types of the two functions have equivalen...
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
const LangOptions & getLangOpts() const
const FunctionProtoType * ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT)
ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, ExceptionSpecificationType &EST)
Check the given noexcept-specifier, convert its expression, and compute the appropriate ExceptionSpec...
AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, QualType Base, QualType Derived, const CXXBasePath &Path, unsigned DiagID, bool ForceCheck=false, bool ForceUnprivileged=false)
Checks access for a hierarchy conversion.
SmallVector< std::pair< const CXXMethodDecl *, const CXXMethodDecl * >, 2 > DelayedOverridingExceptionSpecChecks
All the overriding functions seen during a class definition that had their exception spec checks dela...
bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D)
Determine if we're in a case where we need to (incorrectly) eagerly parse an exception specification ...
bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, const PartialDiagnostic &NestedDiagID, const PartialDiagnostic &NoteID, const PartialDiagnostic &NoThrowDiagID, const FunctionProtoType *Superset, bool SkipSupersetFirstParameter, SourceLocation SuperLoc, const FunctionProtoType *Subset, bool SkipSubsetFirstParameter, SourceLocation SubLoc)
CheckExceptionSpecSubset - Check whether the second function type's exception specification is a subs...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
bool IsDerivedFrom(SourceLocation Loc, CXXRecordDecl *Derived, CXXRecordDecl *Base, CXXBasePaths &Paths)
Determine whether the type Derived is a C++ class that is derived from the type Base.
CanThrowResult canThrow(const Stmt *E)
bool handlerCanCatch(QualType HandlerType, QualType ExceptionType)
bool CheckDistantExceptionSpec(QualType T)
CheckDistantExceptionSpec - Check if the given type is a pointer or pointer to member to a function w...
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New)
bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, const CXXMethodDecl *Old)
CheckOverridingFunctionExceptionSpec - Checks whether the exception spec is a subset of base spec.
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
bool IsFunctionConversion(QualType FromType, QualType ToType) const
Determine whether the conversion from FromType to ToType is a valid conversion of ExtInfo/ExtProtoInf...
bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType)
ASTMutationListener * getASTMutationListener() const
static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, SourceLocation Loc=SourceLocation())
Determine whether the callee of a particular function call can throw.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Stmt - This represents one statement.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
SourceLocation getBeginLoc() const LLVM_READONLY
Base wrapper for a particular "section" of type source info.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
A container of type source information.
bool isSizelessType() const
As an extension, we classify types as one of "sized" or "sizeless"; every type is one or the other.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isMemberPointerType() const
bool isObjectType() const
Determine whether this type is an object type.
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
bool isRecordType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
const Expr * getInit() const
bool isUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value can be used in a constant expression, according to the releva...
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isa(CodeGen::Address addr)
CanThrowResult
Possible results from evaluation of a noexcept expression.
static const FunctionProtoType * GetUnderlyingFunction(QualType T)
bool isDynamicExceptionSpec(ExceptionSpecificationType ESpecType)
static bool CheckEquivalentExceptionSpecImpl(Sema &S, const PartialDiagnostic &DiagID, const PartialDiagnostic &NoteID, const FunctionProtoType *Old, SourceLocation OldLoc, const FunctionProtoType *New, SourceLocation NewLoc, bool *MissingExceptionSpecification=nullptr, bool *MissingEmptyExceptionSpecification=nullptr, bool AllowNoexceptAllMatchWithNoSpec=false, bool IsOperatorNew=false)
CheckEquivalentExceptionSpec - Check if the two types have compatible exception specifications.
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
@ Success
Annotation was successful.
static bool hasImplicitExceptionSpec(FunctionDecl *Decl)
Determine whether a function has an implicitly-generated exception specification.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
CanThrowResult mergeCanThrow(CanThrowResult CT1, CanThrowResult CT2)
@ Result
The result type of a method or function.
static CanThrowResult canVarDeclThrow(Sema &Self, const VarDecl *VD)
static CanThrowResult canDynamicCastThrow(const CXXDynamicCastExpr *DC)
static CanThrowResult canSubStmtsThrow(Sema &Self, const Stmt *S)
static CanThrowResult canTypeidThrow(Sema &S, const CXXTypeidExpr *DC)
static bool CheckSpecForTypesEquivalent(Sema &S, const PartialDiagnostic &DiagID, const PartialDiagnostic &NoteID, QualType Target, SourceLocation TargetLoc, QualType Source, SourceLocation SourceLoc)
U cast(CodeGen::Address addr)
@ Noexcept
Condition in a noexcept(bool) specifier.
ActionResult< Expr * > ExprResult
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_Uninstantiated
not instantiated yet
@ EST_Unparsed
not parsed yet
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
static bool exceptionSpecNotKnownYet(const FunctionDecl *FD)
Holds information about the various types of exception specification.
ExceptionSpecificationType Type
The kind of exception specification this is.