1 //===--- SemaExceptionSpec.cpp - C++ Exception Specifications ---*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file provides Sema routines for C++ exception specification testing. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Sema/SemaInternal.h" 15 #include "clang/AST/ASTMutationListener.h" 16 #include "clang/AST/CXXInheritance.h" 17 #include "clang/AST/Expr.h" 18 #include "clang/AST/ExprCXX.h" 19 #include "clang/AST/TypeLoc.h" 20 #include "clang/Basic/Diagnostic.h" 21 #include "clang/Basic/SourceManager.h" 22 #include "llvm/ADT/SmallPtrSet.h" 23 #include "llvm/ADT/SmallString.h" 24 25 namespace clang { 26 27 static const FunctionProtoType *GetUnderlyingFunction(QualType T) 28 { 29 if (const PointerType *PtrTy = T->getAs<PointerType>()) 30 T = PtrTy->getPointeeType(); 31 else if (const ReferenceType *RefTy = T->getAs<ReferenceType>()) 32 T = RefTy->getPointeeType(); 33 else if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) 34 T = MPTy->getPointeeType(); 35 return T->getAs<FunctionProtoType>(); 36 } 37 38 /// HACK: libstdc++ has a bug where it shadows std::swap with a member 39 /// swap function then tries to call std::swap unqualified from the exception 40 /// specification of that function. This function detects whether we're in 41 /// such a case and turns off delay-parsing of exception specifications. 42 bool Sema::isLibstdcxxEagerExceptionSpecHack(const Declarator &D) { 43 auto *RD = dyn_cast<CXXRecordDecl>(CurContext); 44 45 // All the problem cases are member functions named "swap" within class 46 // templates declared directly within namespace std. 47 if (!RD || RD->getEnclosingNamespaceContext() != getStdNamespace() || 48 !RD->getIdentifier() || !RD->getDescribedClassTemplate() || 49 !D.getIdentifier() || !D.getIdentifier()->isStr("swap")) 50 return false; 51 52 // Only apply this hack within a system header. 53 if (!Context.getSourceManager().isInSystemHeader(D.getLocStart())) 54 return false; 55 56 return llvm::StringSwitch<bool>(RD->getIdentifier()->getName()) 57 .Case("array", true) 58 .Case("pair", true) 59 .Case("priority_queue", true) 60 .Case("stack", true) 61 .Case("queue", true) 62 .Default(false); 63 } 64 65 /// CheckSpecifiedExceptionType - Check if the given type is valid in an 66 /// exception specification. Incomplete types, or pointers to incomplete types 67 /// other than void are not allowed. 68 /// 69 /// \param[in,out] T The exception type. This will be decayed to a pointer type 70 /// when the input is an array or a function type. 71 bool Sema::CheckSpecifiedExceptionType(QualType &T, const SourceRange &Range) { 72 // C++11 [except.spec]p2: 73 // A type cv T, "array of T", or "function returning T" denoted 74 // in an exception-specification is adjusted to type T, "pointer to T", or 75 // "pointer to function returning T", respectively. 76 // 77 // We also apply this rule in C++98. 78 if (T->isArrayType()) 79 T = Context.getArrayDecayedType(T); 80 else if (T->isFunctionType()) 81 T = Context.getPointerType(T); 82 83 int Kind = 0; 84 QualType PointeeT = T; 85 if (const PointerType *PT = T->getAs<PointerType>()) { 86 PointeeT = PT->getPointeeType(); 87 Kind = 1; 88 89 // cv void* is explicitly permitted, despite being a pointer to an 90 // incomplete type. 91 if (PointeeT->isVoidType()) 92 return false; 93 } else if (const ReferenceType *RT = T->getAs<ReferenceType>()) { 94 PointeeT = RT->getPointeeType(); 95 Kind = 2; 96 97 if (RT->isRValueReferenceType()) { 98 // C++11 [except.spec]p2: 99 // A type denoted in an exception-specification shall not denote [...] 100 // an rvalue reference type. 101 Diag(Range.getBegin(), diag::err_rref_in_exception_spec) 102 << T << Range; 103 return true; 104 } 105 } 106 107 // C++11 [except.spec]p2: 108 // A type denoted in an exception-specification shall not denote an 109 // incomplete type other than a class currently being defined [...]. 110 // A type denoted in an exception-specification shall not denote a 111 // pointer or reference to an incomplete type, other than (cv) void* or a 112 // pointer or reference to a class currently being defined. 113 if (!(PointeeT->isRecordType() && 114 PointeeT->getAs<RecordType>()->isBeingDefined()) && 115 RequireCompleteType(Range.getBegin(), PointeeT, 116 diag::err_incomplete_in_exception_spec, Kind, Range)) 117 return true; 118 119 return false; 120 } 121 122 /// CheckDistantExceptionSpec - Check if the given type is a pointer or pointer 123 /// to member to a function with an exception specification. This means that 124 /// it is invalid to add another level of indirection. 125 bool Sema::CheckDistantExceptionSpec(QualType T) { 126 if (const PointerType *PT = T->getAs<PointerType>()) 127 T = PT->getPointeeType(); 128 else if (const MemberPointerType *PT = T->getAs<MemberPointerType>()) 129 T = PT->getPointeeType(); 130 else 131 return false; 132 133 const FunctionProtoType *FnT = T->getAs<FunctionProtoType>(); 134 if (!FnT) 135 return false; 136 137 return FnT->hasExceptionSpec(); 138 } 139 140 const FunctionProtoType * 141 Sema::ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT) { 142 if (FPT->getExceptionSpecType() == EST_Unparsed) { 143 Diag(Loc, diag::err_exception_spec_not_parsed); 144 return nullptr; 145 } 146 147 if (!isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) 148 return FPT; 149 150 FunctionDecl *SourceDecl = FPT->getExceptionSpecDecl(); 151 const FunctionProtoType *SourceFPT = 152 SourceDecl->getType()->castAs<FunctionProtoType>(); 153 154 // If the exception specification has already been resolved, just return it. 155 if (!isUnresolvedExceptionSpec(SourceFPT->getExceptionSpecType())) 156 return SourceFPT; 157 158 // Compute or instantiate the exception specification now. 159 if (SourceFPT->getExceptionSpecType() == EST_Unevaluated) 160 EvaluateImplicitExceptionSpec(Loc, cast<CXXMethodDecl>(SourceDecl)); 161 else 162 InstantiateExceptionSpec(Loc, SourceDecl); 163 164 const FunctionProtoType *Proto = 165 SourceDecl->getType()->castAs<FunctionProtoType>(); 166 if (Proto->getExceptionSpecType() == clang::EST_Unparsed) { 167 Diag(Loc, diag::err_exception_spec_not_parsed); 168 Proto = nullptr; 169 } 170 return Proto; 171 } 172 173 void 174 Sema::UpdateExceptionSpec(FunctionDecl *FD, 175 const FunctionProtoType::ExceptionSpecInfo &ESI) { 176 // If we've fully resolved the exception specification, notify listeners. 177 if (!isUnresolvedExceptionSpec(ESI.Type)) 178 if (auto *Listener = getASTMutationListener()) 179 Listener->ResolvedExceptionSpec(FD); 180 181 for (auto *Redecl : FD->redecls()) 182 Context.adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); 183 } 184 185 /// Determine whether a function has an implicitly-generated exception 186 /// specification. 187 static bool hasImplicitExceptionSpec(FunctionDecl *Decl) { 188 if (!isa<CXXDestructorDecl>(Decl) && 189 Decl->getDeclName().getCXXOverloadedOperator() != OO_Delete && 190 Decl->getDeclName().getCXXOverloadedOperator() != OO_Array_Delete) 191 return false; 192 193 // For a function that the user didn't declare: 194 // - if this is a destructor, its exception specification is implicit. 195 // - if this is 'operator delete' or 'operator delete[]', the exception 196 // specification is as-if an explicit exception specification was given 197 // (per [basic.stc.dynamic]p2). 198 if (!Decl->getTypeSourceInfo()) 199 return isa<CXXDestructorDecl>(Decl); 200 201 const FunctionProtoType *Ty = 202 Decl->getTypeSourceInfo()->getType()->getAs<FunctionProtoType>(); 203 return !Ty->hasExceptionSpec(); 204 } 205 206 bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { 207 OverloadedOperatorKind OO = New->getDeclName().getCXXOverloadedOperator(); 208 bool IsOperatorNew = OO == OO_New || OO == OO_Array_New; 209 bool MissingExceptionSpecification = false; 210 bool MissingEmptyExceptionSpecification = false; 211 212 unsigned DiagID = diag::err_mismatched_exception_spec; 213 bool ReturnValueOnError = true; 214 if (getLangOpts().MicrosoftExt) { 215 DiagID = diag::ext_mismatched_exception_spec; 216 ReturnValueOnError = false; 217 } 218 219 // Check the types as written: they must match before any exception 220 // specification adjustment is applied. 221 if (!CheckEquivalentExceptionSpec( 222 PDiag(DiagID), PDiag(diag::note_previous_declaration), 223 Old->getType()->getAs<FunctionProtoType>(), Old->getLocation(), 224 New->getType()->getAs<FunctionProtoType>(), New->getLocation(), 225 &MissingExceptionSpecification, &MissingEmptyExceptionSpecification, 226 /*AllowNoexceptAllMatchWithNoSpec=*/true, IsOperatorNew)) { 227 // C++11 [except.spec]p4 [DR1492]: 228 // If a declaration of a function has an implicit 229 // exception-specification, other declarations of the function shall 230 // not specify an exception-specification. 231 if (getLangOpts().CPlusPlus11 && 232 hasImplicitExceptionSpec(Old) != hasImplicitExceptionSpec(New)) { 233 Diag(New->getLocation(), diag::ext_implicit_exception_spec_mismatch) 234 << hasImplicitExceptionSpec(Old); 235 if (!Old->getLocation().isInvalid()) 236 Diag(Old->getLocation(), diag::note_previous_declaration); 237 } 238 return false; 239 } 240 241 // The failure was something other than an missing exception 242 // specification; return an error, except in MS mode where this is a warning. 243 if (!MissingExceptionSpecification) 244 return ReturnValueOnError; 245 246 const FunctionProtoType *NewProto = 247 New->getType()->castAs<FunctionProtoType>(); 248 249 // The new function declaration is only missing an empty exception 250 // specification "throw()". If the throw() specification came from a 251 // function in a system header that has C linkage, just add an empty 252 // exception specification to the "new" declaration. This is an 253 // egregious workaround for glibc, which adds throw() specifications 254 // to many libc functions as an optimization. Unfortunately, that 255 // optimization isn't permitted by the C++ standard, so we're forced 256 // to work around it here. 257 if (MissingEmptyExceptionSpecification && NewProto && 258 (Old->getLocation().isInvalid() || 259 Context.getSourceManager().isInSystemHeader(Old->getLocation())) && 260 Old->isExternC()) { 261 New->setType(Context.getFunctionType( 262 NewProto->getReturnType(), NewProto->getParamTypes(), 263 NewProto->getExtProtoInfo().withExceptionSpec(EST_DynamicNone))); 264 return false; 265 } 266 267 const FunctionProtoType *OldProto = 268 Old->getType()->castAs<FunctionProtoType>(); 269 270 FunctionProtoType::ExceptionSpecInfo ESI = OldProto->getExceptionSpecType(); 271 if (ESI.Type == EST_Dynamic) { 272 ESI.Exceptions = OldProto->exceptions(); 273 } else if (ESI.Type == EST_ComputedNoexcept) { 274 // FIXME: We can't just take the expression from the old prototype. It 275 // likely contains references to the old prototype's parameters. 276 } 277 278 // Update the type of the function with the appropriate exception 279 // specification. 280 New->setType(Context.getFunctionType( 281 NewProto->getReturnType(), NewProto->getParamTypes(), 282 NewProto->getExtProtoInfo().withExceptionSpec(ESI))); 283 284 // Warn about the lack of exception specification. 285 SmallString<128> ExceptionSpecString; 286 llvm::raw_svector_ostream OS(ExceptionSpecString); 287 switch (OldProto->getExceptionSpecType()) { 288 case EST_DynamicNone: 289 OS << "throw()"; 290 break; 291 292 case EST_Dynamic: { 293 OS << "throw("; 294 bool OnFirstException = true; 295 for (const auto &E : OldProto->exceptions()) { 296 if (OnFirstException) 297 OnFirstException = false; 298 else 299 OS << ", "; 300 301 OS << E.getAsString(getPrintingPolicy()); 302 } 303 OS << ")"; 304 break; 305 } 306 307 case EST_BasicNoexcept: 308 OS << "noexcept"; 309 break; 310 311 case EST_ComputedNoexcept: 312 OS << "noexcept("; 313 assert(OldProto->getNoexceptExpr() != nullptr && "Expected non-null Expr"); 314 OldProto->getNoexceptExpr()->printPretty(OS, nullptr, getPrintingPolicy()); 315 OS << ")"; 316 break; 317 318 default: 319 llvm_unreachable("This spec type is compatible with none."); 320 } 321 322 SourceLocation FixItLoc; 323 if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) { 324 TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens(); 325 if (FunctionTypeLoc FTLoc = TL.getAs<FunctionTypeLoc>()) 326 FixItLoc = getLocForEndOfToken(FTLoc.getLocalRangeEnd()); 327 } 328 329 if (FixItLoc.isInvalid()) 330 Diag(New->getLocation(), diag::warn_missing_exception_specification) 331 << New << OS.str(); 332 else { 333 // FIXME: This will get more complicated with C++0x 334 // late-specified return types. 335 Diag(New->getLocation(), diag::warn_missing_exception_specification) 336 << New << OS.str() 337 << FixItHint::CreateInsertion(FixItLoc, " " + OS.str().str()); 338 } 339 340 if (!Old->getLocation().isInvalid()) 341 Diag(Old->getLocation(), diag::note_previous_declaration); 342 343 return false; 344 } 345 346 /// CheckEquivalentExceptionSpec - Check if the two types have equivalent 347 /// exception specifications. Exception specifications are equivalent if 348 /// they allow exactly the same set of exception types. It does not matter how 349 /// that is achieved. See C++ [except.spec]p2. 350 bool Sema::CheckEquivalentExceptionSpec( 351 const FunctionProtoType *Old, SourceLocation OldLoc, 352 const FunctionProtoType *New, SourceLocation NewLoc) { 353 unsigned DiagID = diag::err_mismatched_exception_spec; 354 if (getLangOpts().MicrosoftExt) 355 DiagID = diag::ext_mismatched_exception_spec; 356 bool Result = CheckEquivalentExceptionSpec(PDiag(DiagID), 357 PDiag(diag::note_previous_declaration), Old, OldLoc, New, NewLoc); 358 359 // In Microsoft mode, mismatching exception specifications just cause a warning. 360 if (getLangOpts().MicrosoftExt) 361 return false; 362 return Result; 363 } 364 365 /// CheckEquivalentExceptionSpec - Check if the two types have compatible 366 /// exception specifications. See C++ [except.spec]p3. 367 /// 368 /// \return \c false if the exception specifications match, \c true if there is 369 /// a problem. If \c true is returned, either a diagnostic has already been 370 /// produced or \c *MissingExceptionSpecification is set to \c true. 371 bool Sema::CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID, 372 const PartialDiagnostic & NoteID, 373 const FunctionProtoType *Old, 374 SourceLocation OldLoc, 375 const FunctionProtoType *New, 376 SourceLocation NewLoc, 377 bool *MissingExceptionSpecification, 378 bool*MissingEmptyExceptionSpecification, 379 bool AllowNoexceptAllMatchWithNoSpec, 380 bool IsOperatorNew) { 381 // Just completely ignore this under -fno-exceptions. 382 if (!getLangOpts().CXXExceptions) 383 return false; 384 385 if (MissingExceptionSpecification) 386 *MissingExceptionSpecification = false; 387 388 if (MissingEmptyExceptionSpecification) 389 *MissingEmptyExceptionSpecification = false; 390 391 Old = ResolveExceptionSpec(NewLoc, Old); 392 if (!Old) 393 return false; 394 New = ResolveExceptionSpec(NewLoc, New); 395 if (!New) 396 return false; 397 398 // C++0x [except.spec]p3: Two exception-specifications are compatible if: 399 // - both are non-throwing, regardless of their form, 400 // - both have the form noexcept(constant-expression) and the constant- 401 // expressions are equivalent, 402 // - both are dynamic-exception-specifications that have the same set of 403 // adjusted types. 404 // 405 // C++0x [except.spec]p12: An exception-specification is non-throwing if it is 406 // of the form throw(), noexcept, or noexcept(constant-expression) where the 407 // constant-expression yields true. 408 // 409 // C++0x [except.spec]p4: If any declaration of a function has an exception- 410 // specifier that is not a noexcept-specification allowing all exceptions, 411 // all declarations [...] of that function shall have a compatible 412 // exception-specification. 413 // 414 // That last point basically means that noexcept(false) matches no spec. 415 // It's considered when AllowNoexceptAllMatchWithNoSpec is true. 416 417 ExceptionSpecificationType OldEST = Old->getExceptionSpecType(); 418 ExceptionSpecificationType NewEST = New->getExceptionSpecType(); 419 420 assert(!isUnresolvedExceptionSpec(OldEST) && 421 !isUnresolvedExceptionSpec(NewEST) && 422 "Shouldn't see unknown exception specifications here"); 423 424 // Shortcut the case where both have no spec. 425 if (OldEST == EST_None && NewEST == EST_None) 426 return false; 427 428 FunctionProtoType::NoexceptResult OldNR = Old->getNoexceptSpec(Context); 429 FunctionProtoType::NoexceptResult NewNR = New->getNoexceptSpec(Context); 430 if (OldNR == FunctionProtoType::NR_BadNoexcept || 431 NewNR == FunctionProtoType::NR_BadNoexcept) 432 return false; 433 434 // Dependent noexcept specifiers are compatible with each other, but nothing 435 // else. 436 // One noexcept is compatible with another if the argument is the same 437 if (OldNR == NewNR && 438 OldNR != FunctionProtoType::NR_NoNoexcept && 439 NewNR != FunctionProtoType::NR_NoNoexcept) 440 return false; 441 if (OldNR != NewNR && 442 OldNR != FunctionProtoType::NR_NoNoexcept && 443 NewNR != FunctionProtoType::NR_NoNoexcept) { 444 Diag(NewLoc, DiagID); 445 if (NoteID.getDiagID() != 0 && OldLoc.isValid()) 446 Diag(OldLoc, NoteID); 447 return true; 448 } 449 450 // The MS extension throw(...) is compatible with itself. 451 if (OldEST == EST_MSAny && NewEST == EST_MSAny) 452 return false; 453 454 // It's also compatible with no spec. 455 if ((OldEST == EST_None && NewEST == EST_MSAny) || 456 (OldEST == EST_MSAny && NewEST == EST_None)) 457 return false; 458 459 // It's also compatible with noexcept(false). 460 if (OldEST == EST_MSAny && NewNR == FunctionProtoType::NR_Throw) 461 return false; 462 if (NewEST == EST_MSAny && OldNR == FunctionProtoType::NR_Throw) 463 return false; 464 465 // As described above, noexcept(false) matches no spec only for functions. 466 if (AllowNoexceptAllMatchWithNoSpec) { 467 if (OldEST == EST_None && NewNR == FunctionProtoType::NR_Throw) 468 return false; 469 if (NewEST == EST_None && OldNR == FunctionProtoType::NR_Throw) 470 return false; 471 } 472 473 // Any non-throwing specifications are compatible. 474 bool OldNonThrowing = OldNR == FunctionProtoType::NR_Nothrow || 475 OldEST == EST_DynamicNone; 476 bool NewNonThrowing = NewNR == FunctionProtoType::NR_Nothrow || 477 NewEST == EST_DynamicNone; 478 if (OldNonThrowing && NewNonThrowing) 479 return false; 480 481 // As a special compatibility feature, under C++0x we accept no spec and 482 // throw(std::bad_alloc) as equivalent for operator new and operator new[]. 483 // This is because the implicit declaration changed, but old code would break. 484 if (getLangOpts().CPlusPlus11 && IsOperatorNew) { 485 const FunctionProtoType *WithExceptions = nullptr; 486 if (OldEST == EST_None && NewEST == EST_Dynamic) 487 WithExceptions = New; 488 else if (OldEST == EST_Dynamic && NewEST == EST_None) 489 WithExceptions = Old; 490 if (WithExceptions && WithExceptions->getNumExceptions() == 1) { 491 // One has no spec, the other throw(something). If that something is 492 // std::bad_alloc, all conditions are met. 493 QualType Exception = *WithExceptions->exception_begin(); 494 if (CXXRecordDecl *ExRecord = Exception->getAsCXXRecordDecl()) { 495 IdentifierInfo* Name = ExRecord->getIdentifier(); 496 if (Name && Name->getName() == "bad_alloc") { 497 // It's called bad_alloc, but is it in std? 498 if (ExRecord->isInStdNamespace()) { 499 return false; 500 } 501 } 502 } 503 } 504 } 505 506 // At this point, the only remaining valid case is two matching dynamic 507 // specifications. We return here unless both specifications are dynamic. 508 if (OldEST != EST_Dynamic || NewEST != EST_Dynamic) { 509 if (MissingExceptionSpecification && Old->hasExceptionSpec() && 510 !New->hasExceptionSpec()) { 511 // The old type has an exception specification of some sort, but 512 // the new type does not. 513 *MissingExceptionSpecification = true; 514 515 if (MissingEmptyExceptionSpecification && OldNonThrowing) { 516 // The old type has a throw() or noexcept(true) exception specification 517 // and the new type has no exception specification, and the caller asked 518 // to handle this itself. 519 *MissingEmptyExceptionSpecification = true; 520 } 521 522 return true; 523 } 524 525 Diag(NewLoc, DiagID); 526 if (NoteID.getDiagID() != 0 && OldLoc.isValid()) 527 Diag(OldLoc, NoteID); 528 return true; 529 } 530 531 assert(OldEST == EST_Dynamic && NewEST == EST_Dynamic && 532 "Exception compatibility logic error: non-dynamic spec slipped through."); 533 534 bool Success = true; 535 // Both have a dynamic exception spec. Collect the first set, then compare 536 // to the second. 537 llvm::SmallPtrSet<CanQualType, 8> OldTypes, NewTypes; 538 for (const auto &I : Old->exceptions()) 539 OldTypes.insert(Context.getCanonicalType(I).getUnqualifiedType()); 540 541 for (const auto &I : New->exceptions()) { 542 CanQualType TypePtr = Context.getCanonicalType(I).getUnqualifiedType(); 543 if(OldTypes.count(TypePtr)) 544 NewTypes.insert(TypePtr); 545 else 546 Success = false; 547 } 548 549 Success = Success && OldTypes.size() == NewTypes.size(); 550 551 if (Success) { 552 return false; 553 } 554 Diag(NewLoc, DiagID); 555 if (NoteID.getDiagID() != 0 && OldLoc.isValid()) 556 Diag(OldLoc, NoteID); 557 return true; 558 } 559 560 /// CheckExceptionSpecSubset - Check whether the second function type's 561 /// exception specification is a subset (or equivalent) of the first function 562 /// type. This is used by override and pointer assignment checks. 563 bool Sema::CheckExceptionSpecSubset( 564 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 565 const FunctionProtoType *Superset, SourceLocation SuperLoc, 566 const FunctionProtoType *Subset, SourceLocation SubLoc) { 567 568 // Just auto-succeed under -fno-exceptions. 569 if (!getLangOpts().CXXExceptions) 570 return false; 571 572 // FIXME: As usual, we could be more specific in our error messages, but 573 // that better waits until we've got types with source locations. 574 575 if (!SubLoc.isValid()) 576 SubLoc = SuperLoc; 577 578 // Resolve the exception specifications, if needed. 579 Superset = ResolveExceptionSpec(SuperLoc, Superset); 580 if (!Superset) 581 return false; 582 Subset = ResolveExceptionSpec(SubLoc, Subset); 583 if (!Subset) 584 return false; 585 586 ExceptionSpecificationType SuperEST = Superset->getExceptionSpecType(); 587 588 // If superset contains everything, we're done. 589 if (SuperEST == EST_None || SuperEST == EST_MSAny) 590 return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc); 591 592 // If there are dependent noexcept specs, assume everything is fine. Unlike 593 // with the equivalency check, this is safe in this case, because we don't 594 // want to merge declarations. Checks after instantiation will catch any 595 // omissions we make here. 596 // We also shortcut checking if a noexcept expression was bad. 597 598 FunctionProtoType::NoexceptResult SuperNR =Superset->getNoexceptSpec(Context); 599 if (SuperNR == FunctionProtoType::NR_BadNoexcept || 600 SuperNR == FunctionProtoType::NR_Dependent) 601 return false; 602 603 // Another case of the superset containing everything. 604 if (SuperNR == FunctionProtoType::NR_Throw) 605 return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc); 606 607 ExceptionSpecificationType SubEST = Subset->getExceptionSpecType(); 608 609 assert(!isUnresolvedExceptionSpec(SuperEST) && 610 !isUnresolvedExceptionSpec(SubEST) && 611 "Shouldn't see unknown exception specifications here"); 612 613 // It does not. If the subset contains everything, we've failed. 614 if (SubEST == EST_None || SubEST == EST_MSAny) { 615 Diag(SubLoc, DiagID); 616 if (NoteID.getDiagID() != 0) 617 Diag(SuperLoc, NoteID); 618 return true; 619 } 620 621 FunctionProtoType::NoexceptResult SubNR = Subset->getNoexceptSpec(Context); 622 if (SubNR == FunctionProtoType::NR_BadNoexcept || 623 SubNR == FunctionProtoType::NR_Dependent) 624 return false; 625 626 // Another case of the subset containing everything. 627 if (SubNR == FunctionProtoType::NR_Throw) { 628 Diag(SubLoc, DiagID); 629 if (NoteID.getDiagID() != 0) 630 Diag(SuperLoc, NoteID); 631 return true; 632 } 633 634 // If the subset contains nothing, we're done. 635 if (SubEST == EST_DynamicNone || SubNR == FunctionProtoType::NR_Nothrow) 636 return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc); 637 638 // Otherwise, if the superset contains nothing, we've failed. 639 if (SuperEST == EST_DynamicNone || SuperNR == FunctionProtoType::NR_Nothrow) { 640 Diag(SubLoc, DiagID); 641 if (NoteID.getDiagID() != 0) 642 Diag(SuperLoc, NoteID); 643 return true; 644 } 645 646 assert(SuperEST == EST_Dynamic && SubEST == EST_Dynamic && 647 "Exception spec subset: non-dynamic case slipped through."); 648 649 // Neither contains everything or nothing. Do a proper comparison. 650 for (const auto &SubI : Subset->exceptions()) { 651 // Take one type from the subset. 652 QualType CanonicalSubT = Context.getCanonicalType(SubI); 653 // Unwrap pointers and references so that we can do checks within a class 654 // hierarchy. Don't unwrap member pointers; they don't have hierarchy 655 // conversions on the pointee. 656 bool SubIsPointer = false; 657 if (const ReferenceType *RefTy = CanonicalSubT->getAs<ReferenceType>()) 658 CanonicalSubT = RefTy->getPointeeType(); 659 if (const PointerType *PtrTy = CanonicalSubT->getAs<PointerType>()) { 660 CanonicalSubT = PtrTy->getPointeeType(); 661 SubIsPointer = true; 662 } 663 bool SubIsClass = CanonicalSubT->isRecordType(); 664 CanonicalSubT = CanonicalSubT.getLocalUnqualifiedType(); 665 666 CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, 667 /*DetectVirtual=*/false); 668 669 bool Contained = false; 670 // Make sure it's in the superset. 671 for (const auto &SuperI : Superset->exceptions()) { 672 QualType CanonicalSuperT = Context.getCanonicalType(SuperI); 673 // SubT must be SuperT or derived from it, or pointer or reference to 674 // such types. 675 if (const ReferenceType *RefTy = CanonicalSuperT->getAs<ReferenceType>()) 676 CanonicalSuperT = RefTy->getPointeeType(); 677 if (SubIsPointer) { 678 if (const PointerType *PtrTy = CanonicalSuperT->getAs<PointerType>()) 679 CanonicalSuperT = PtrTy->getPointeeType(); 680 else { 681 continue; 682 } 683 } 684 CanonicalSuperT = CanonicalSuperT.getLocalUnqualifiedType(); 685 // If the types are the same, move on to the next type in the subset. 686 if (CanonicalSubT == CanonicalSuperT) { 687 Contained = true; 688 break; 689 } 690 691 // Otherwise we need to check the inheritance. 692 if (!SubIsClass || !CanonicalSuperT->isRecordType()) 693 continue; 694 695 Paths.clear(); 696 if (!IsDerivedFrom(CanonicalSubT, CanonicalSuperT, Paths)) 697 continue; 698 699 if (Paths.isAmbiguous(Context.getCanonicalType(CanonicalSuperT))) 700 continue; 701 702 // Do this check from a context without privileges. 703 switch (CheckBaseClassAccess(SourceLocation(), 704 CanonicalSuperT, CanonicalSubT, 705 Paths.front(), 706 /*Diagnostic*/ 0, 707 /*ForceCheck*/ true, 708 /*ForceUnprivileged*/ true)) { 709 case AR_accessible: break; 710 case AR_inaccessible: continue; 711 case AR_dependent: 712 llvm_unreachable("access check dependent for unprivileged context"); 713 case AR_delayed: 714 llvm_unreachable("access check delayed in non-declaration"); 715 } 716 717 Contained = true; 718 break; 719 } 720 if (!Contained) { 721 Diag(SubLoc, DiagID); 722 if (NoteID.getDiagID() != 0) 723 Diag(SuperLoc, NoteID); 724 return true; 725 } 726 } 727 // We've run half the gauntlet. 728 return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc); 729 } 730 731 static bool CheckSpecForTypesEquivalent(Sema &S, 732 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 733 QualType Target, SourceLocation TargetLoc, 734 QualType Source, SourceLocation SourceLoc) 735 { 736 const FunctionProtoType *TFunc = GetUnderlyingFunction(Target); 737 if (!TFunc) 738 return false; 739 const FunctionProtoType *SFunc = GetUnderlyingFunction(Source); 740 if (!SFunc) 741 return false; 742 743 return S.CheckEquivalentExceptionSpec(DiagID, NoteID, TFunc, TargetLoc, 744 SFunc, SourceLoc); 745 } 746 747 /// CheckParamExceptionSpec - Check if the parameter and return types of the 748 /// two functions have equivalent exception specs. This is part of the 749 /// assignment and override compatibility check. We do not check the parameters 750 /// of parameter function pointers recursively, as no sane programmer would 751 /// even be able to write such a function type. 752 bool Sema::CheckParamExceptionSpec(const PartialDiagnostic &NoteID, 753 const FunctionProtoType *Target, 754 SourceLocation TargetLoc, 755 const FunctionProtoType *Source, 756 SourceLocation SourceLoc) { 757 if (CheckSpecForTypesEquivalent( 758 *this, PDiag(diag::err_deep_exception_specs_differ) << 0, PDiag(), 759 Target->getReturnType(), TargetLoc, Source->getReturnType(), 760 SourceLoc)) 761 return true; 762 763 // We shouldn't even be testing this unless the arguments are otherwise 764 // compatible. 765 assert(Target->getNumParams() == Source->getNumParams() && 766 "Functions have different argument counts."); 767 for (unsigned i = 0, E = Target->getNumParams(); i != E; ++i) { 768 if (CheckSpecForTypesEquivalent( 769 *this, PDiag(diag::err_deep_exception_specs_differ) << 1, PDiag(), 770 Target->getParamType(i), TargetLoc, Source->getParamType(i), 771 SourceLoc)) 772 return true; 773 } 774 return false; 775 } 776 777 bool Sema::CheckExceptionSpecCompatibility(Expr *From, QualType ToType) { 778 // First we check for applicability. 779 // Target type must be a function, function pointer or function reference. 780 const FunctionProtoType *ToFunc = GetUnderlyingFunction(ToType); 781 if (!ToFunc || ToFunc->hasDependentExceptionSpec()) 782 return false; 783 784 // SourceType must be a function or function pointer. 785 const FunctionProtoType *FromFunc = GetUnderlyingFunction(From->getType()); 786 if (!FromFunc || FromFunc->hasDependentExceptionSpec()) 787 return false; 788 789 // Now we've got the correct types on both sides, check their compatibility. 790 // This means that the source of the conversion can only throw a subset of 791 // the exceptions of the target, and any exception specs on arguments or 792 // return types must be equivalent. 793 // 794 // FIXME: If there is a nested dependent exception specification, we should 795 // not be checking it here. This is fine: 796 // template<typename T> void f() { 797 // void (*p)(void (*) throw(T)); 798 // void (*q)(void (*) throw(int)) = p; 799 // } 800 // ... because it might be instantiated with T=int. 801 return CheckExceptionSpecSubset(PDiag(diag::err_incompatible_exception_specs), 802 PDiag(), ToFunc, 803 From->getSourceRange().getBegin(), 804 FromFunc, SourceLocation()); 805 } 806 807 bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 808 const CXXMethodDecl *Old) { 809 // If the new exception specification hasn't been parsed yet, skip the check. 810 // We'll get called again once it's been parsed. 811 if (New->getType()->castAs<FunctionProtoType>()->getExceptionSpecType() == 812 EST_Unparsed) 813 return false; 814 if (getLangOpts().CPlusPlus11 && isa<CXXDestructorDecl>(New)) { 815 // Don't check uninstantiated template destructors at all. We can only 816 // synthesize correct specs after the template is instantiated. 817 if (New->getParent()->isDependentType()) 818 return false; 819 if (New->getParent()->isBeingDefined()) { 820 // The destructor might be updated once the definition is finished. So 821 // remember it and check later. 822 DelayedExceptionSpecChecks.push_back(std::make_pair(New, Old)); 823 return false; 824 } 825 } 826 // If the old exception specification hasn't been parsed yet, remember that 827 // we need to perform this check when we get to the end of the outermost 828 // lexically-surrounding class. 829 if (Old->getType()->castAs<FunctionProtoType>()->getExceptionSpecType() == 830 EST_Unparsed) { 831 DelayedExceptionSpecChecks.push_back(std::make_pair(New, Old)); 832 return false; 833 } 834 unsigned DiagID = diag::err_override_exception_spec; 835 if (getLangOpts().MicrosoftExt) 836 DiagID = diag::ext_override_exception_spec; 837 return CheckExceptionSpecSubset(PDiag(DiagID), 838 PDiag(diag::note_overridden_virtual_function), 839 Old->getType()->getAs<FunctionProtoType>(), 840 Old->getLocation(), 841 New->getType()->getAs<FunctionProtoType>(), 842 New->getLocation()); 843 } 844 845 static CanThrowResult canSubExprsThrow(Sema &S, const Expr *E) { 846 CanThrowResult R = CT_Cannot; 847 for (const Stmt *SubStmt : E->children()) { 848 R = mergeCanThrow(R, S.canThrow(cast<Expr>(SubStmt))); 849 if (R == CT_Can) 850 break; 851 } 852 return R; 853 } 854 855 static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D) { 856 assert(D && "Expected decl"); 857 858 // See if we can get a function type from the decl somehow. 859 const ValueDecl *VD = dyn_cast<ValueDecl>(D); 860 if (!VD) // If we have no clue what we're calling, assume the worst. 861 return CT_Can; 862 863 // As an extension, we assume that __attribute__((nothrow)) functions don't 864 // throw. 865 if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>()) 866 return CT_Cannot; 867 868 QualType T = VD->getType(); 869 const FunctionProtoType *FT; 870 if ((FT = T->getAs<FunctionProtoType>())) { 871 } else if (const PointerType *PT = T->getAs<PointerType>()) 872 FT = PT->getPointeeType()->getAs<FunctionProtoType>(); 873 else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 874 FT = RT->getPointeeType()->getAs<FunctionProtoType>(); 875 else if (const MemberPointerType *MT = T->getAs<MemberPointerType>()) 876 FT = MT->getPointeeType()->getAs<FunctionProtoType>(); 877 else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) 878 FT = BT->getPointeeType()->getAs<FunctionProtoType>(); 879 880 if (!FT) 881 return CT_Can; 882 883 FT = S.ResolveExceptionSpec(E->getLocStart(), FT); 884 if (!FT) 885 return CT_Can; 886 887 return FT->isNothrow(S.Context) ? CT_Cannot : CT_Can; 888 } 889 890 static CanThrowResult canDynamicCastThrow(const CXXDynamicCastExpr *DC) { 891 if (DC->isTypeDependent()) 892 return CT_Dependent; 893 894 if (!DC->getTypeAsWritten()->isReferenceType()) 895 return CT_Cannot; 896 897 if (DC->getSubExpr()->isTypeDependent()) 898 return CT_Dependent; 899 900 return DC->getCastKind() == clang::CK_Dynamic? CT_Can : CT_Cannot; 901 } 902 903 static CanThrowResult canTypeidThrow(Sema &S, const CXXTypeidExpr *DC) { 904 if (DC->isTypeOperand()) 905 return CT_Cannot; 906 907 Expr *Op = DC->getExprOperand(); 908 if (Op->isTypeDependent()) 909 return CT_Dependent; 910 911 const RecordType *RT = Op->getType()->getAs<RecordType>(); 912 if (!RT) 913 return CT_Cannot; 914 915 if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic()) 916 return CT_Cannot; 917 918 if (Op->Classify(S.Context).isPRValue()) 919 return CT_Cannot; 920 921 return CT_Can; 922 } 923 924 CanThrowResult Sema::canThrow(const Expr *E) { 925 // C++ [expr.unary.noexcept]p3: 926 // [Can throw] if in a potentially-evaluated context the expression would 927 // contain: 928 switch (E->getStmtClass()) { 929 case Expr::CXXThrowExprClass: 930 // - a potentially evaluated throw-expression 931 return CT_Can; 932 933 case Expr::CXXDynamicCastExprClass: { 934 // - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), 935 // where T is a reference type, that requires a run-time check 936 CanThrowResult CT = canDynamicCastThrow(cast<CXXDynamicCastExpr>(E)); 937 if (CT == CT_Can) 938 return CT; 939 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 940 } 941 942 case Expr::CXXTypeidExprClass: 943 // - a potentially evaluated typeid expression applied to a glvalue 944 // expression whose type is a polymorphic class type 945 return canTypeidThrow(*this, cast<CXXTypeidExpr>(E)); 946 947 // - a potentially evaluated call to a function, member function, function 948 // pointer, or member function pointer that does not have a non-throwing 949 // exception-specification 950 case Expr::CallExprClass: 951 case Expr::CXXMemberCallExprClass: 952 case Expr::CXXOperatorCallExprClass: 953 case Expr::UserDefinedLiteralClass: { 954 const CallExpr *CE = cast<CallExpr>(E); 955 CanThrowResult CT; 956 if (E->isTypeDependent()) 957 CT = CT_Dependent; 958 else if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens())) 959 CT = CT_Cannot; 960 else if (CE->getCalleeDecl()) 961 CT = canCalleeThrow(*this, E, CE->getCalleeDecl()); 962 else 963 CT = CT_Can; 964 if (CT == CT_Can) 965 return CT; 966 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 967 } 968 969 case Expr::CXXConstructExprClass: 970 case Expr::CXXTemporaryObjectExprClass: { 971 CanThrowResult CT = canCalleeThrow(*this, E, 972 cast<CXXConstructExpr>(E)->getConstructor()); 973 if (CT == CT_Can) 974 return CT; 975 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 976 } 977 978 case Expr::LambdaExprClass: { 979 const LambdaExpr *Lambda = cast<LambdaExpr>(E); 980 CanThrowResult CT = CT_Cannot; 981 for (LambdaExpr::const_capture_init_iterator 982 Cap = Lambda->capture_init_begin(), 983 CapEnd = Lambda->capture_init_end(); 984 Cap != CapEnd; ++Cap) 985 CT = mergeCanThrow(CT, canThrow(*Cap)); 986 return CT; 987 } 988 989 case Expr::CXXNewExprClass: { 990 CanThrowResult CT; 991 if (E->isTypeDependent()) 992 CT = CT_Dependent; 993 else 994 CT = canCalleeThrow(*this, E, cast<CXXNewExpr>(E)->getOperatorNew()); 995 if (CT == CT_Can) 996 return CT; 997 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 998 } 999 1000 case Expr::CXXDeleteExprClass: { 1001 CanThrowResult CT; 1002 QualType DTy = cast<CXXDeleteExpr>(E)->getDestroyedType(); 1003 if (DTy.isNull() || DTy->isDependentType()) { 1004 CT = CT_Dependent; 1005 } else { 1006 CT = canCalleeThrow(*this, E, 1007 cast<CXXDeleteExpr>(E)->getOperatorDelete()); 1008 if (const RecordType *RT = DTy->getAs<RecordType>()) { 1009 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); 1010 const CXXDestructorDecl *DD = RD->getDestructor(); 1011 if (DD) 1012 CT = mergeCanThrow(CT, canCalleeThrow(*this, E, DD)); 1013 } 1014 if (CT == CT_Can) 1015 return CT; 1016 } 1017 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 1018 } 1019 1020 case Expr::CXXBindTemporaryExprClass: { 1021 // The bound temporary has to be destroyed again, which might throw. 1022 CanThrowResult CT = canCalleeThrow(*this, E, 1023 cast<CXXBindTemporaryExpr>(E)->getTemporary()->getDestructor()); 1024 if (CT == CT_Can) 1025 return CT; 1026 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 1027 } 1028 1029 // ObjC message sends are like function calls, but never have exception 1030 // specs. 1031 case Expr::ObjCMessageExprClass: 1032 case Expr::ObjCPropertyRefExprClass: 1033 case Expr::ObjCSubscriptRefExprClass: 1034 return CT_Can; 1035 1036 // All the ObjC literals that are implemented as calls are 1037 // potentially throwing unless we decide to close off that 1038 // possibility. 1039 case Expr::ObjCArrayLiteralClass: 1040 case Expr::ObjCDictionaryLiteralClass: 1041 case Expr::ObjCBoxedExprClass: 1042 return CT_Can; 1043 1044 // Many other things have subexpressions, so we have to test those. 1045 // Some are simple: 1046 case Expr::ConditionalOperatorClass: 1047 case Expr::CompoundLiteralExprClass: 1048 case Expr::CXXConstCastExprClass: 1049 case Expr::CXXReinterpretCastExprClass: 1050 case Expr::CXXStdInitializerListExprClass: 1051 case Expr::DesignatedInitExprClass: 1052 case Expr::DesignatedInitUpdateExprClass: 1053 case Expr::ExprWithCleanupsClass: 1054 case Expr::ExtVectorElementExprClass: 1055 case Expr::InitListExprClass: 1056 case Expr::MemberExprClass: 1057 case Expr::ObjCIsaExprClass: 1058 case Expr::ObjCIvarRefExprClass: 1059 case Expr::ParenExprClass: 1060 case Expr::ParenListExprClass: 1061 case Expr::ShuffleVectorExprClass: 1062 case Expr::ConvertVectorExprClass: 1063 case Expr::VAArgExprClass: 1064 return canSubExprsThrow(*this, E); 1065 1066 // Some might be dependent for other reasons. 1067 case Expr::ArraySubscriptExprClass: 1068 case Expr::OMPArraySectionExprClass: 1069 case Expr::BinaryOperatorClass: 1070 case Expr::CompoundAssignOperatorClass: 1071 case Expr::CStyleCastExprClass: 1072 case Expr::CXXStaticCastExprClass: 1073 case Expr::CXXFunctionalCastExprClass: 1074 case Expr::ImplicitCastExprClass: 1075 case Expr::MaterializeTemporaryExprClass: 1076 case Expr::UnaryOperatorClass: { 1077 CanThrowResult CT = E->isTypeDependent() ? CT_Dependent : CT_Cannot; 1078 return mergeCanThrow(CT, canSubExprsThrow(*this, E)); 1079 } 1080 1081 // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms. 1082 case Expr::StmtExprClass: 1083 return CT_Can; 1084 1085 case Expr::CXXDefaultArgExprClass: 1086 return canThrow(cast<CXXDefaultArgExpr>(E)->getExpr()); 1087 1088 case Expr::CXXDefaultInitExprClass: 1089 return canThrow(cast<CXXDefaultInitExpr>(E)->getExpr()); 1090 1091 case Expr::ChooseExprClass: 1092 if (E->isTypeDependent() || E->isValueDependent()) 1093 return CT_Dependent; 1094 return canThrow(cast<ChooseExpr>(E)->getChosenSubExpr()); 1095 1096 case Expr::GenericSelectionExprClass: 1097 if (cast<GenericSelectionExpr>(E)->isResultDependent()) 1098 return CT_Dependent; 1099 return canThrow(cast<GenericSelectionExpr>(E)->getResultExpr()); 1100 1101 // Some expressions are always dependent. 1102 case Expr::CXXDependentScopeMemberExprClass: 1103 case Expr::CXXUnresolvedConstructExprClass: 1104 case Expr::DependentScopeDeclRefExprClass: 1105 case Expr::CXXFoldExprClass: 1106 return CT_Dependent; 1107 1108 case Expr::AsTypeExprClass: 1109 case Expr::BinaryConditionalOperatorClass: 1110 case Expr::BlockExprClass: 1111 case Expr::CUDAKernelCallExprClass: 1112 case Expr::DeclRefExprClass: 1113 case Expr::ObjCBridgedCastExprClass: 1114 case Expr::ObjCIndirectCopyRestoreExprClass: 1115 case Expr::ObjCProtocolExprClass: 1116 case Expr::ObjCSelectorExprClass: 1117 case Expr::OffsetOfExprClass: 1118 case Expr::PackExpansionExprClass: 1119 case Expr::PseudoObjectExprClass: 1120 case Expr::SubstNonTypeTemplateParmExprClass: 1121 case Expr::SubstNonTypeTemplateParmPackExprClass: 1122 case Expr::FunctionParmPackExprClass: 1123 case Expr::UnaryExprOrTypeTraitExprClass: 1124 case Expr::UnresolvedLookupExprClass: 1125 case Expr::UnresolvedMemberExprClass: 1126 case Expr::TypoExprClass: 1127 // FIXME: Can any of the above throw? If so, when? 1128 return CT_Cannot; 1129 1130 case Expr::AddrLabelExprClass: 1131 case Expr::ArrayTypeTraitExprClass: 1132 case Expr::AtomicExprClass: 1133 case Expr::TypeTraitExprClass: 1134 case Expr::CXXBoolLiteralExprClass: 1135 case Expr::CXXNoexceptExprClass: 1136 case Expr::CXXNullPtrLiteralExprClass: 1137 case Expr::CXXPseudoDestructorExprClass: 1138 case Expr::CXXScalarValueInitExprClass: 1139 case Expr::CXXThisExprClass: 1140 case Expr::CXXUuidofExprClass: 1141 case Expr::CharacterLiteralClass: 1142 case Expr::ExpressionTraitExprClass: 1143 case Expr::FloatingLiteralClass: 1144 case Expr::GNUNullExprClass: 1145 case Expr::ImaginaryLiteralClass: 1146 case Expr::ImplicitValueInitExprClass: 1147 case Expr::IntegerLiteralClass: 1148 case Expr::NoInitExprClass: 1149 case Expr::ObjCEncodeExprClass: 1150 case Expr::ObjCStringLiteralClass: 1151 case Expr::ObjCBoolLiteralExprClass: 1152 case Expr::OpaqueValueExprClass: 1153 case Expr::PredefinedExprClass: 1154 case Expr::SizeOfPackExprClass: 1155 case Expr::StringLiteralClass: 1156 // These expressions can never throw. 1157 return CT_Cannot; 1158 1159 case Expr::MSPropertyRefExprClass: 1160 llvm_unreachable("Invalid class for expression"); 1161 1162 #define STMT(CLASS, PARENT) case Expr::CLASS##Class: 1163 #define STMT_RANGE(Base, First, Last) 1164 #define LAST_STMT_RANGE(BASE, FIRST, LAST) 1165 #define EXPR(CLASS, PARENT) 1166 #define ABSTRACT_STMT(STMT) 1167 #include "clang/AST/StmtNodes.inc" 1168 case Expr::NoStmtClass: 1169 llvm_unreachable("Invalid class for expression"); 1170 } 1171 llvm_unreachable("Bogus StmtClass"); 1172 } 1173 1174 } // end namespace clang 1175