SemaExceptionSpec.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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. #include "clang/Sema/SemaInternal.h"
  14. #include "clang/AST/CXXInheritance.h"
  15. #include "clang/AST/Expr.h"
  16. #include "clang/AST/ExprCXX.h"
  17. #include "clang/AST/TypeLoc.h"
  18. #include "clang/Lex/Preprocessor.h"
  19. #include "clang/Basic/Diagnostic.h"
  20. #include "clang/Basic/SourceManager.h"
  21. #include "llvm/ADT/SmallPtrSet.h"
  22. #include "llvm/ADT/SmallString.h"
  23. namespace clang {
  24. static const FunctionProtoType *GetUnderlyingFunction(QualType T)
  25. {
  26. if (const PointerType *PtrTy = T->getAs<PointerType>())
  27. T = PtrTy->getPointeeType();
  28. else if (const ReferenceType *RefTy = T->getAs<ReferenceType>())
  29. T = RefTy->getPointeeType();
  30. else if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>())
  31. T = MPTy->getPointeeType();
  32. return T->getAs<FunctionProtoType>();
  33. }
  34. /// CheckSpecifiedExceptionType - Check if the given type is valid in an
  35. /// exception specification. Incomplete types, or pointers to incomplete types
  36. /// other than void are not allowed.
  37. bool Sema::CheckSpecifiedExceptionType(QualType T, const SourceRange &Range) {
  38. // This check (and the similar one below) deals with issue 437, that changes
  39. // C++ 9.2p2 this way:
  40. // Within the class member-specification, the class is regarded as complete
  41. // within function bodies, default arguments, exception-specifications, and
  42. // constructor ctor-initializers (including such things in nested classes).
  43. if (T->isRecordType() && T->getAs<RecordType>()->isBeingDefined())
  44. return false;
  45. // C++ 15.4p2: A type denoted in an exception-specification shall not denote
  46. // an incomplete type.
  47. if (RequireCompleteType(Range.getBegin(), T,
  48. diag::err_incomplete_in_exception_spec,
  49. /*direct*/0, Range))
  50. return true;
  51. // C++ 15.4p2: A type denoted in an exception-specification shall not denote
  52. // an incomplete type a pointer or reference to an incomplete type, other
  53. // than (cv) void*.
  54. int kind;
  55. if (const PointerType* IT = T->getAs<PointerType>()) {
  56. T = IT->getPointeeType();
  57. kind = 1;
  58. } else if (const ReferenceType* IT = T->getAs<ReferenceType>()) {
  59. T = IT->getPointeeType();
  60. kind = 2;
  61. } else
  62. return false;
  63. // Again as before
  64. if (T->isRecordType() && T->getAs<RecordType>()->isBeingDefined())
  65. return false;
  66. if (!T->isVoidType() &&
  67. RequireCompleteType(Range.getBegin(), T,
  68. diag::err_incomplete_in_exception_spec, kind, Range))
  69. return true;
  70. return false;
  71. }
  72. /// CheckDistantExceptionSpec - Check if the given type is a pointer or pointer
  73. /// to member to a function with an exception specification. This means that
  74. /// it is invalid to add another level of indirection.
  75. bool Sema::CheckDistantExceptionSpec(QualType T) {
  76. if (const PointerType *PT = T->getAs<PointerType>())
  77. T = PT->getPointeeType();
  78. else if (const MemberPointerType *PT = T->getAs<MemberPointerType>())
  79. T = PT->getPointeeType();
  80. else
  81. return false;
  82. const FunctionProtoType *FnT = T->getAs<FunctionProtoType>();
  83. if (!FnT)
  84. return false;
  85. return FnT->hasExceptionSpec();
  86. }
  87. const FunctionProtoType *
  88. Sema::ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT) {
  89. if (!isUnresolvedExceptionSpec(FPT->getExceptionSpecType()))
  90. return FPT;
  91. FunctionDecl *SourceDecl = FPT->getExceptionSpecDecl();
  92. const FunctionProtoType *SourceFPT =
  93. SourceDecl->getType()->castAs<FunctionProtoType>();
  94. // If the exception specification has already been resolved, just return it.
  95. if (!isUnresolvedExceptionSpec(SourceFPT->getExceptionSpecType()))
  96. return SourceFPT;
  97. // Compute or instantiate the exception specification now.
  98. if (FPT->getExceptionSpecType() == EST_Unevaluated)
  99. EvaluateImplicitExceptionSpec(Loc, cast<CXXMethodDecl>(SourceDecl));
  100. else
  101. InstantiateExceptionSpec(Loc, SourceDecl);
  102. return SourceDecl->getType()->castAs<FunctionProtoType>();
  103. }
  104. bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
  105. OverloadedOperatorKind OO = New->getDeclName().getCXXOverloadedOperator();
  106. bool IsOperatorNew = OO == OO_New || OO == OO_Array_New;
  107. bool MissingExceptionSpecification = false;
  108. bool MissingEmptyExceptionSpecification = false;
  109. unsigned DiagID = diag::err_mismatched_exception_spec;
  110. if (getLangOpts().MicrosoftExt)
  111. DiagID = diag::warn_mismatched_exception_spec;
  112. if (!CheckEquivalentExceptionSpec(PDiag(DiagID),
  113. PDiag(diag::note_previous_declaration),
  114. Old->getType()->getAs<FunctionProtoType>(),
  115. Old->getLocation(),
  116. New->getType()->getAs<FunctionProtoType>(),
  117. New->getLocation(),
  118. &MissingExceptionSpecification,
  119. &MissingEmptyExceptionSpecification,
  120. /*AllowNoexceptAllMatchWithNoSpec=*/true,
  121. IsOperatorNew))
  122. return false;
  123. // The failure was something other than an empty exception
  124. // specification; return an error.
  125. if (!MissingExceptionSpecification && !MissingEmptyExceptionSpecification)
  126. return true;
  127. const FunctionProtoType *NewProto
  128. = New->getType()->getAs<FunctionProtoType>();
  129. // The new function declaration is only missing an empty exception
  130. // specification "throw()". If the throw() specification came from a
  131. // function in a system header that has C linkage, just add an empty
  132. // exception specification to the "new" declaration. This is an
  133. // egregious workaround for glibc, which adds throw() specifications
  134. // to many libc functions as an optimization. Unfortunately, that
  135. // optimization isn't permitted by the C++ standard, so we're forced
  136. // to work around it here.
  137. if (MissingEmptyExceptionSpecification && NewProto &&
  138. (Old->getLocation().isInvalid() ||
  139. Context.getSourceManager().isInSystemHeader(Old->getLocation())) &&
  140. Old->isExternC()) {
  141. FunctionProtoType::ExtProtoInfo EPI = NewProto->getExtProtoInfo();
  142. EPI.ExceptionSpecType = EST_DynamicNone;
  143. QualType NewType = Context.getFunctionType(NewProto->getResultType(),
  144. NewProto->arg_type_begin(),
  145. NewProto->getNumArgs(),
  146. EPI);
  147. New->setType(NewType);
  148. return false;
  149. }
  150. if (MissingExceptionSpecification && NewProto) {
  151. const FunctionProtoType *OldProto
  152. = Old->getType()->getAs<FunctionProtoType>();
  153. FunctionProtoType::ExtProtoInfo EPI = NewProto->getExtProtoInfo();
  154. EPI.ExceptionSpecType = OldProto->getExceptionSpecType();
  155. if (EPI.ExceptionSpecType == EST_Dynamic) {
  156. EPI.NumExceptions = OldProto->getNumExceptions();
  157. EPI.Exceptions = OldProto->exception_begin();
  158. } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
  159. // FIXME: We can't just take the expression from the old prototype. It
  160. // likely contains references to the old prototype's parameters.
  161. }
  162. // Update the type of the function with the appropriate exception
  163. // specification.
  164. QualType NewType = Context.getFunctionType(NewProto->getResultType(),
  165. NewProto->arg_type_begin(),
  166. NewProto->getNumArgs(),
  167. EPI);
  168. New->setType(NewType);
  169. // If exceptions are disabled, suppress the warning about missing
  170. // exception specifications for new and delete operators.
  171. if (!getLangOpts().CXXExceptions) {
  172. switch (New->getDeclName().getCXXOverloadedOperator()) {
  173. case OO_New:
  174. case OO_Array_New:
  175. case OO_Delete:
  176. case OO_Array_Delete:
  177. if (New->getDeclContext()->isTranslationUnit())
  178. return false;
  179. break;
  180. default:
  181. break;
  182. }
  183. }
  184. // Warn about the lack of exception specification.
  185. SmallString<128> ExceptionSpecString;
  186. llvm::raw_svector_ostream OS(ExceptionSpecString);
  187. switch (OldProto->getExceptionSpecType()) {
  188. case EST_DynamicNone:
  189. OS << "throw()";
  190. break;
  191. case EST_Dynamic: {
  192. OS << "throw(";
  193. bool OnFirstException = true;
  194. for (FunctionProtoType::exception_iterator E = OldProto->exception_begin(),
  195. EEnd = OldProto->exception_end();
  196. E != EEnd;
  197. ++E) {
  198. if (OnFirstException)
  199. OnFirstException = false;
  200. else
  201. OS << ", ";
  202. OS << E->getAsString(getPrintingPolicy());
  203. }
  204. OS << ")";
  205. break;
  206. }
  207. case EST_BasicNoexcept:
  208. OS << "noexcept";
  209. break;
  210. case EST_ComputedNoexcept:
  211. OS << "noexcept(";
  212. OldProto->getNoexceptExpr()->printPretty(OS, 0, getPrintingPolicy());
  213. OS << ")";
  214. break;
  215. default:
  216. llvm_unreachable("This spec type is compatible with none.");
  217. }
  218. OS.flush();
  219. SourceLocation FixItLoc;
  220. if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) {
  221. TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
  222. if (const FunctionTypeLoc *FTLoc = dyn_cast<FunctionTypeLoc>(&TL))
  223. FixItLoc = PP.getLocForEndOfToken(FTLoc->getLocalRangeEnd());
  224. }
  225. if (FixItLoc.isInvalid())
  226. Diag(New->getLocation(), diag::warn_missing_exception_specification)
  227. << New << OS.str();
  228. else {
  229. // FIXME: This will get more complicated with C++0x
  230. // late-specified return types.
  231. Diag(New->getLocation(), diag::warn_missing_exception_specification)
  232. << New << OS.str()
  233. << FixItHint::CreateInsertion(FixItLoc, " " + OS.str().str());
  234. }
  235. if (!Old->getLocation().isInvalid())
  236. Diag(Old->getLocation(), diag::note_previous_declaration);
  237. return false;
  238. }
  239. Diag(New->getLocation(), DiagID);
  240. Diag(Old->getLocation(), diag::note_previous_declaration);
  241. return true;
  242. }
  243. /// CheckEquivalentExceptionSpec - Check if the two types have equivalent
  244. /// exception specifications. Exception specifications are equivalent if
  245. /// they allow exactly the same set of exception types. It does not matter how
  246. /// that is achieved. See C++ [except.spec]p2.
  247. bool Sema::CheckEquivalentExceptionSpec(
  248. const FunctionProtoType *Old, SourceLocation OldLoc,
  249. const FunctionProtoType *New, SourceLocation NewLoc) {
  250. unsigned DiagID = diag::err_mismatched_exception_spec;
  251. if (getLangOpts().MicrosoftExt)
  252. DiagID = diag::warn_mismatched_exception_spec;
  253. return CheckEquivalentExceptionSpec(
  254. PDiag(DiagID),
  255. PDiag(diag::note_previous_declaration),
  256. Old, OldLoc, New, NewLoc);
  257. }
  258. /// CheckEquivalentExceptionSpec - Check if the two types have compatible
  259. /// exception specifications. See C++ [except.spec]p3.
  260. bool Sema::CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID,
  261. const PartialDiagnostic & NoteID,
  262. const FunctionProtoType *Old,
  263. SourceLocation OldLoc,
  264. const FunctionProtoType *New,
  265. SourceLocation NewLoc,
  266. bool *MissingExceptionSpecification,
  267. bool*MissingEmptyExceptionSpecification,
  268. bool AllowNoexceptAllMatchWithNoSpec,
  269. bool IsOperatorNew) {
  270. // Just completely ignore this under -fno-exceptions.
  271. if (!getLangOpts().CXXExceptions)
  272. return false;
  273. if (MissingExceptionSpecification)
  274. *MissingExceptionSpecification = false;
  275. if (MissingEmptyExceptionSpecification)
  276. *MissingEmptyExceptionSpecification = false;
  277. Old = ResolveExceptionSpec(NewLoc, Old);
  278. if (!Old)
  279. return false;
  280. New = ResolveExceptionSpec(NewLoc, New);
  281. if (!New)
  282. return false;
  283. // C++0x [except.spec]p3: Two exception-specifications are compatible if:
  284. // - both are non-throwing, regardless of their form,
  285. // - both have the form noexcept(constant-expression) and the constant-
  286. // expressions are equivalent,
  287. // - both are dynamic-exception-specifications that have the same set of
  288. // adjusted types.
  289. //
  290. // C++0x [except.spec]p12: An exception-specifcation is non-throwing if it is
  291. // of the form throw(), noexcept, or noexcept(constant-expression) where the
  292. // constant-expression yields true.
  293. //
  294. // C++0x [except.spec]p4: If any declaration of a function has an exception-
  295. // specifier that is not a noexcept-specification allowing all exceptions,
  296. // all declarations [...] of that function shall have a compatible
  297. // exception-specification.
  298. //
  299. // That last point basically means that noexcept(false) matches no spec.
  300. // It's considered when AllowNoexceptAllMatchWithNoSpec is true.
  301. ExceptionSpecificationType OldEST = Old->getExceptionSpecType();
  302. ExceptionSpecificationType NewEST = New->getExceptionSpecType();
  303. assert(!isUnresolvedExceptionSpec(OldEST) &&
  304. !isUnresolvedExceptionSpec(NewEST) &&
  305. "Shouldn't see unknown exception specifications here");
  306. // Shortcut the case where both have no spec.
  307. if (OldEST == EST_None && NewEST == EST_None)
  308. return false;
  309. FunctionProtoType::NoexceptResult OldNR = Old->getNoexceptSpec(Context);
  310. FunctionProtoType::NoexceptResult NewNR = New->getNoexceptSpec(Context);
  311. if (OldNR == FunctionProtoType::NR_BadNoexcept ||
  312. NewNR == FunctionProtoType::NR_BadNoexcept)
  313. return false;
  314. // Dependent noexcept specifiers are compatible with each other, but nothing
  315. // else.
  316. // One noexcept is compatible with another if the argument is the same
  317. if (OldNR == NewNR &&
  318. OldNR != FunctionProtoType::NR_NoNoexcept &&
  319. NewNR != FunctionProtoType::NR_NoNoexcept)
  320. return false;
  321. if (OldNR != NewNR &&
  322. OldNR != FunctionProtoType::NR_NoNoexcept &&
  323. NewNR != FunctionProtoType::NR_NoNoexcept) {
  324. Diag(NewLoc, DiagID);
  325. if (NoteID.getDiagID() != 0)
  326. Diag(OldLoc, NoteID);
  327. return true;
  328. }
  329. // The MS extension throw(...) is compatible with itself.
  330. if (OldEST == EST_MSAny && NewEST == EST_MSAny)
  331. return false;
  332. // It's also compatible with no spec.
  333. if ((OldEST == EST_None && NewEST == EST_MSAny) ||
  334. (OldEST == EST_MSAny && NewEST == EST_None))
  335. return false;
  336. // It's also compatible with noexcept(false).
  337. if (OldEST == EST_MSAny && NewNR == FunctionProtoType::NR_Throw)
  338. return false;
  339. if (NewEST == EST_MSAny && OldNR == FunctionProtoType::NR_Throw)
  340. return false;
  341. // As described above, noexcept(false) matches no spec only for functions.
  342. if (AllowNoexceptAllMatchWithNoSpec) {
  343. if (OldEST == EST_None && NewNR == FunctionProtoType::NR_Throw)
  344. return false;
  345. if (NewEST == EST_None && OldNR == FunctionProtoType::NR_Throw)
  346. return false;
  347. }
  348. // Any non-throwing specifications are compatible.
  349. bool OldNonThrowing = OldNR == FunctionProtoType::NR_Nothrow ||
  350. OldEST == EST_DynamicNone;
  351. bool NewNonThrowing = NewNR == FunctionProtoType::NR_Nothrow ||
  352. NewEST == EST_DynamicNone;
  353. if (OldNonThrowing && NewNonThrowing)
  354. return false;
  355. // As a special compatibility feature, under C++0x we accept no spec and
  356. // throw(std::bad_alloc) as equivalent for operator new and operator new[].
  357. // This is because the implicit declaration changed, but old code would break.
  358. if (getLangOpts().CPlusPlus0x && IsOperatorNew) {
  359. const FunctionProtoType *WithExceptions = 0;
  360. if (OldEST == EST_None && NewEST == EST_Dynamic)
  361. WithExceptions = New;
  362. else if (OldEST == EST_Dynamic && NewEST == EST_None)
  363. WithExceptions = Old;
  364. if (WithExceptions && WithExceptions->getNumExceptions() == 1) {
  365. // One has no spec, the other throw(something). If that something is
  366. // std::bad_alloc, all conditions are met.
  367. QualType Exception = *WithExceptions->exception_begin();
  368. if (CXXRecordDecl *ExRecord = Exception->getAsCXXRecordDecl()) {
  369. IdentifierInfo* Name = ExRecord->getIdentifier();
  370. if (Name && Name->getName() == "bad_alloc") {
  371. // It's called bad_alloc, but is it in std?
  372. DeclContext* DC = ExRecord->getDeclContext();
  373. DC = DC->getEnclosingNamespaceContext();
  374. if (NamespaceDecl* NS = dyn_cast<NamespaceDecl>(DC)) {
  375. IdentifierInfo* NSName = NS->getIdentifier();
  376. DC = DC->getParent();
  377. if (NSName && NSName->getName() == "std" &&
  378. DC->getEnclosingNamespaceContext()->isTranslationUnit()) {
  379. return false;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386. // At this point, the only remaining valid case is two matching dynamic
  387. // specifications. We return here unless both specifications are dynamic.
  388. if (OldEST != EST_Dynamic || NewEST != EST_Dynamic) {
  389. if (MissingExceptionSpecification && Old->hasExceptionSpec() &&
  390. !New->hasExceptionSpec()) {
  391. // The old type has an exception specification of some sort, but
  392. // the new type does not.
  393. *MissingExceptionSpecification = true;
  394. if (MissingEmptyExceptionSpecification && OldNonThrowing) {
  395. // The old type has a throw() or noexcept(true) exception specification
  396. // and the new type has no exception specification, and the caller asked
  397. // to handle this itself.
  398. *MissingEmptyExceptionSpecification = true;
  399. }
  400. return true;
  401. }
  402. Diag(NewLoc, DiagID);
  403. if (NoteID.getDiagID() != 0)
  404. Diag(OldLoc, NoteID);
  405. return true;
  406. }
  407. assert(OldEST == EST_Dynamic && NewEST == EST_Dynamic &&
  408. "Exception compatibility logic error: non-dynamic spec slipped through.");
  409. bool Success = true;
  410. // Both have a dynamic exception spec. Collect the first set, then compare
  411. // to the second.
  412. llvm::SmallPtrSet<CanQualType, 8> OldTypes, NewTypes;
  413. for (FunctionProtoType::exception_iterator I = Old->exception_begin(),
  414. E = Old->exception_end(); I != E; ++I)
  415. OldTypes.insert(Context.getCanonicalType(*I).getUnqualifiedType());
  416. for (FunctionProtoType::exception_iterator I = New->exception_begin(),
  417. E = New->exception_end(); I != E && Success; ++I) {
  418. CanQualType TypePtr = Context.getCanonicalType(*I).getUnqualifiedType();
  419. if(OldTypes.count(TypePtr))
  420. NewTypes.insert(TypePtr);
  421. else
  422. Success = false;
  423. }
  424. Success = Success && OldTypes.size() == NewTypes.size();
  425. if (Success) {
  426. return false;
  427. }
  428. Diag(NewLoc, DiagID);
  429. if (NoteID.getDiagID() != 0)
  430. Diag(OldLoc, NoteID);
  431. return true;
  432. }
  433. /// CheckExceptionSpecSubset - Check whether the second function type's
  434. /// exception specification is a subset (or equivalent) of the first function
  435. /// type. This is used by override and pointer assignment checks.
  436. bool Sema::CheckExceptionSpecSubset(
  437. const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
  438. const FunctionProtoType *Superset, SourceLocation SuperLoc,
  439. const FunctionProtoType *Subset, SourceLocation SubLoc) {
  440. // Just auto-succeed under -fno-exceptions.
  441. if (!getLangOpts().CXXExceptions)
  442. return false;
  443. // FIXME: As usual, we could be more specific in our error messages, but
  444. // that better waits until we've got types with source locations.
  445. if (!SubLoc.isValid())
  446. SubLoc = SuperLoc;
  447. // Resolve the exception specifications, if needed.
  448. Superset = ResolveExceptionSpec(SuperLoc, Superset);
  449. if (!Superset)
  450. return false;
  451. Subset = ResolveExceptionSpec(SubLoc, Subset);
  452. if (!Subset)
  453. return false;
  454. ExceptionSpecificationType SuperEST = Superset->getExceptionSpecType();
  455. // If superset contains everything, we're done.
  456. if (SuperEST == EST_None || SuperEST == EST_MSAny)
  457. return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
  458. // If there are dependent noexcept specs, assume everything is fine. Unlike
  459. // with the equivalency check, this is safe in this case, because we don't
  460. // want to merge declarations. Checks after instantiation will catch any
  461. // omissions we make here.
  462. // We also shortcut checking if a noexcept expression was bad.
  463. FunctionProtoType::NoexceptResult SuperNR =Superset->getNoexceptSpec(Context);
  464. if (SuperNR == FunctionProtoType::NR_BadNoexcept ||
  465. SuperNR == FunctionProtoType::NR_Dependent)
  466. return false;
  467. // Another case of the superset containing everything.
  468. if (SuperNR == FunctionProtoType::NR_Throw)
  469. return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
  470. ExceptionSpecificationType SubEST = Subset->getExceptionSpecType();
  471. assert(!isUnresolvedExceptionSpec(SuperEST) &&
  472. !isUnresolvedExceptionSpec(SubEST) &&
  473. "Shouldn't see unknown exception specifications here");
  474. // It does not. If the subset contains everything, we've failed.
  475. if (SubEST == EST_None || SubEST == EST_MSAny) {
  476. Diag(SubLoc, DiagID);
  477. if (NoteID.getDiagID() != 0)
  478. Diag(SuperLoc, NoteID);
  479. return true;
  480. }
  481. FunctionProtoType::NoexceptResult SubNR = Subset->getNoexceptSpec(Context);
  482. if (SubNR == FunctionProtoType::NR_BadNoexcept ||
  483. SubNR == FunctionProtoType::NR_Dependent)
  484. return false;
  485. // Another case of the subset containing everything.
  486. if (SubNR == FunctionProtoType::NR_Throw) {
  487. Diag(SubLoc, DiagID);
  488. if (NoteID.getDiagID() != 0)
  489. Diag(SuperLoc, NoteID);
  490. return true;
  491. }
  492. // If the subset contains nothing, we're done.
  493. if (SubEST == EST_DynamicNone || SubNR == FunctionProtoType::NR_Nothrow)
  494. return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
  495. // Otherwise, if the superset contains nothing, we've failed.
  496. if (SuperEST == EST_DynamicNone || SuperNR == FunctionProtoType::NR_Nothrow) {
  497. Diag(SubLoc, DiagID);
  498. if (NoteID.getDiagID() != 0)
  499. Diag(SuperLoc, NoteID);
  500. return true;
  501. }
  502. assert(SuperEST == EST_Dynamic && SubEST == EST_Dynamic &&
  503. "Exception spec subset: non-dynamic case slipped through.");
  504. // Neither contains everything or nothing. Do a proper comparison.
  505. for (FunctionProtoType::exception_iterator SubI = Subset->exception_begin(),
  506. SubE = Subset->exception_end(); SubI != SubE; ++SubI) {
  507. // Take one type from the subset.
  508. QualType CanonicalSubT = Context.getCanonicalType(*SubI);
  509. // Unwrap pointers and references so that we can do checks within a class
  510. // hierarchy. Don't unwrap member pointers; they don't have hierarchy
  511. // conversions on the pointee.
  512. bool SubIsPointer = false;
  513. if (const ReferenceType *RefTy = CanonicalSubT->getAs<ReferenceType>())
  514. CanonicalSubT = RefTy->getPointeeType();
  515. if (const PointerType *PtrTy = CanonicalSubT->getAs<PointerType>()) {
  516. CanonicalSubT = PtrTy->getPointeeType();
  517. SubIsPointer = true;
  518. }
  519. bool SubIsClass = CanonicalSubT->isRecordType();
  520. CanonicalSubT = CanonicalSubT.getLocalUnqualifiedType();
  521. CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
  522. /*DetectVirtual=*/false);
  523. bool Contained = false;
  524. // Make sure it's in the superset.
  525. for (FunctionProtoType::exception_iterator SuperI =
  526. Superset->exception_begin(), SuperE = Superset->exception_end();
  527. SuperI != SuperE; ++SuperI) {
  528. QualType CanonicalSuperT = Context.getCanonicalType(*SuperI);
  529. // SubT must be SuperT or derived from it, or pointer or reference to
  530. // such types.
  531. if (const ReferenceType *RefTy = CanonicalSuperT->getAs<ReferenceType>())
  532. CanonicalSuperT = RefTy->getPointeeType();
  533. if (SubIsPointer) {
  534. if (const PointerType *PtrTy = CanonicalSuperT->getAs<PointerType>())
  535. CanonicalSuperT = PtrTy->getPointeeType();
  536. else {
  537. continue;
  538. }
  539. }
  540. CanonicalSuperT = CanonicalSuperT.getLocalUnqualifiedType();
  541. // If the types are the same, move on to the next type in the subset.
  542. if (CanonicalSubT == CanonicalSuperT) {
  543. Contained = true;
  544. break;
  545. }
  546. // Otherwise we need to check the inheritance.
  547. if (!SubIsClass || !CanonicalSuperT->isRecordType())
  548. continue;
  549. Paths.clear();
  550. if (!IsDerivedFrom(CanonicalSubT, CanonicalSuperT, Paths))
  551. continue;
  552. if (Paths.isAmbiguous(Context.getCanonicalType(CanonicalSuperT)))
  553. continue;
  554. // Do this check from a context without privileges.
  555. switch (CheckBaseClassAccess(SourceLocation(),
  556. CanonicalSuperT, CanonicalSubT,
  557. Paths.front(),
  558. /*Diagnostic*/ 0,
  559. /*ForceCheck*/ true,
  560. /*ForceUnprivileged*/ true)) {
  561. case AR_accessible: break;
  562. case AR_inaccessible: continue;
  563. case AR_dependent:
  564. llvm_unreachable("access check dependent for unprivileged context");
  565. case AR_delayed:
  566. llvm_unreachable("access check delayed in non-declaration");
  567. }
  568. Contained = true;
  569. break;
  570. }
  571. if (!Contained) {
  572. Diag(SubLoc, DiagID);
  573. if (NoteID.getDiagID() != 0)
  574. Diag(SuperLoc, NoteID);
  575. return true;
  576. }
  577. }
  578. // We've run half the gauntlet.
  579. return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
  580. }
  581. static bool CheckSpecForTypesEquivalent(Sema &S,
  582. const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
  583. QualType Target, SourceLocation TargetLoc,
  584. QualType Source, SourceLocation SourceLoc)
  585. {
  586. const FunctionProtoType *TFunc = GetUnderlyingFunction(Target);
  587. if (!TFunc)
  588. return false;
  589. const FunctionProtoType *SFunc = GetUnderlyingFunction(Source);
  590. if (!SFunc)
  591. return false;
  592. return S.CheckEquivalentExceptionSpec(DiagID, NoteID, TFunc, TargetLoc,
  593. SFunc, SourceLoc);
  594. }
  595. /// CheckParamExceptionSpec - Check if the parameter and return types of the
  596. /// two functions have equivalent exception specs. This is part of the
  597. /// assignment and override compatibility check. We do not check the parameters
  598. /// of parameter function pointers recursively, as no sane programmer would
  599. /// even be able to write such a function type.
  600. bool Sema::CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
  601. const FunctionProtoType *Target, SourceLocation TargetLoc,
  602. const FunctionProtoType *Source, SourceLocation SourceLoc)
  603. {
  604. if (CheckSpecForTypesEquivalent(*this,
  605. PDiag(diag::err_deep_exception_specs_differ) << 0,
  606. PDiag(),
  607. Target->getResultType(), TargetLoc,
  608. Source->getResultType(), SourceLoc))
  609. return true;
  610. // We shouldn't even be testing this unless the arguments are otherwise
  611. // compatible.
  612. assert(Target->getNumArgs() == Source->getNumArgs() &&
  613. "Functions have different argument counts.");
  614. for (unsigned i = 0, E = Target->getNumArgs(); i != E; ++i) {
  615. if (CheckSpecForTypesEquivalent(*this,
  616. PDiag(diag::err_deep_exception_specs_differ) << 1,
  617. PDiag(),
  618. Target->getArgType(i), TargetLoc,
  619. Source->getArgType(i), SourceLoc))
  620. return true;
  621. }
  622. return false;
  623. }
  624. bool Sema::CheckExceptionSpecCompatibility(Expr *From, QualType ToType)
  625. {
  626. // First we check for applicability.
  627. // Target type must be a function, function pointer or function reference.
  628. const FunctionProtoType *ToFunc = GetUnderlyingFunction(ToType);
  629. if (!ToFunc)
  630. return false;
  631. // SourceType must be a function or function pointer.
  632. const FunctionProtoType *FromFunc = GetUnderlyingFunction(From->getType());
  633. if (!FromFunc)
  634. return false;
  635. // Now we've got the correct types on both sides, check their compatibility.
  636. // This means that the source of the conversion can only throw a subset of
  637. // the exceptions of the target, and any exception specs on arguments or
  638. // return types must be equivalent.
  639. return CheckExceptionSpecSubset(PDiag(diag::err_incompatible_exception_specs),
  640. PDiag(), ToFunc,
  641. From->getSourceRange().getBegin(),
  642. FromFunc, SourceLocation());
  643. }
  644. bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
  645. const CXXMethodDecl *Old) {
  646. if (getLangOpts().CPlusPlus0x && isa<CXXDestructorDecl>(New)) {
  647. // Don't check uninstantiated template destructors at all. We can only
  648. // synthesize correct specs after the template is instantiated.
  649. if (New->getParent()->isDependentType())
  650. return false;
  651. if (New->getParent()->isBeingDefined()) {
  652. // The destructor might be updated once the definition is finished. So
  653. // remember it and check later.
  654. DelayedDestructorExceptionSpecChecks.push_back(std::make_pair(
  655. cast<CXXDestructorDecl>(New), cast<CXXDestructorDecl>(Old)));
  656. return false;
  657. }
  658. }
  659. unsigned DiagID = diag::err_override_exception_spec;
  660. if (getLangOpts().MicrosoftExt)
  661. DiagID = diag::warn_override_exception_spec;
  662. return CheckExceptionSpecSubset(PDiag(DiagID),
  663. PDiag(diag::note_overridden_virtual_function),
  664. Old->getType()->getAs<FunctionProtoType>(),
  665. Old->getLocation(),
  666. New->getType()->getAs<FunctionProtoType>(),
  667. New->getLocation());
  668. }
  669. static CanThrowResult canSubExprsThrow(Sema &S, const Expr *CE) {
  670. Expr *E = const_cast<Expr*>(CE);
  671. CanThrowResult R = CT_Cannot;
  672. for (Expr::child_range I = E->children(); I && R != CT_Can; ++I)
  673. R = mergeCanThrow(R, S.canThrow(cast<Expr>(*I)));
  674. return R;
  675. }
  676. static CanThrowResult canCalleeThrow(Sema &S, const Expr *E,
  677. const Decl *D,
  678. bool NullThrows = true) {
  679. if (!D)
  680. return NullThrows ? CT_Can : CT_Cannot;
  681. // See if we can get a function type from the decl somehow.
  682. const ValueDecl *VD = dyn_cast<ValueDecl>(D);
  683. if (!VD) // If we have no clue what we're calling, assume the worst.
  684. return CT_Can;
  685. // As an extension, we assume that __attribute__((nothrow)) functions don't
  686. // throw.
  687. if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>())
  688. return CT_Cannot;
  689. QualType T = VD->getType();
  690. const FunctionProtoType *FT;
  691. if ((FT = T->getAs<FunctionProtoType>())) {
  692. } else if (const PointerType *PT = T->getAs<PointerType>())
  693. FT = PT->getPointeeType()->getAs<FunctionProtoType>();
  694. else if (const ReferenceType *RT = T->getAs<ReferenceType>())
  695. FT = RT->getPointeeType()->getAs<FunctionProtoType>();
  696. else if (const MemberPointerType *MT = T->getAs<MemberPointerType>())
  697. FT = MT->getPointeeType()->getAs<FunctionProtoType>();
  698. else if (const BlockPointerType *BT = T->getAs<BlockPointerType>())
  699. FT = BT->getPointeeType()->getAs<FunctionProtoType>();
  700. if (!FT)
  701. return CT_Can;
  702. FT = S.ResolveExceptionSpec(E->getLocStart(), FT);
  703. if (!FT)
  704. return CT_Can;
  705. return FT->isNothrow(S.Context) ? CT_Cannot : CT_Can;
  706. }
  707. static CanThrowResult canDynamicCastThrow(const CXXDynamicCastExpr *DC) {
  708. if (DC->isTypeDependent())
  709. return CT_Dependent;
  710. if (!DC->getTypeAsWritten()->isReferenceType())
  711. return CT_Cannot;
  712. if (DC->getSubExpr()->isTypeDependent())
  713. return CT_Dependent;
  714. return DC->getCastKind() == clang::CK_Dynamic? CT_Can : CT_Cannot;
  715. }
  716. static CanThrowResult canTypeidThrow(Sema &S, const CXXTypeidExpr *DC) {
  717. if (DC->isTypeOperand())
  718. return CT_Cannot;
  719. Expr *Op = DC->getExprOperand();
  720. if (Op->isTypeDependent())
  721. return CT_Dependent;
  722. const RecordType *RT = Op->getType()->getAs<RecordType>();
  723. if (!RT)
  724. return CT_Cannot;
  725. if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic())
  726. return CT_Cannot;
  727. if (Op->Classify(S.Context).isPRValue())
  728. return CT_Cannot;
  729. return CT_Can;
  730. }
  731. CanThrowResult Sema::canThrow(const Expr *E) {
  732. // C++ [expr.unary.noexcept]p3:
  733. // [Can throw] if in a potentially-evaluated context the expression would
  734. // contain:
  735. switch (E->getStmtClass()) {
  736. case Expr::CXXThrowExprClass:
  737. // - a potentially evaluated throw-expression
  738. return CT_Can;
  739. case Expr::CXXDynamicCastExprClass: {
  740. // - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v),
  741. // where T is a reference type, that requires a run-time check
  742. CanThrowResult CT = canDynamicCastThrow(cast<CXXDynamicCastExpr>(E));
  743. if (CT == CT_Can)
  744. return CT;
  745. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  746. }
  747. case Expr::CXXTypeidExprClass:
  748. // - a potentially evaluated typeid expression applied to a glvalue
  749. // expression whose type is a polymorphic class type
  750. return canTypeidThrow(*this, cast<CXXTypeidExpr>(E));
  751. // - a potentially evaluated call to a function, member function, function
  752. // pointer, or member function pointer that does not have a non-throwing
  753. // exception-specification
  754. case Expr::CallExprClass:
  755. case Expr::CXXMemberCallExprClass:
  756. case Expr::CXXOperatorCallExprClass:
  757. case Expr::UserDefinedLiteralClass: {
  758. const CallExpr *CE = cast<CallExpr>(E);
  759. CanThrowResult CT;
  760. if (E->isTypeDependent())
  761. CT = CT_Dependent;
  762. else if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens()))
  763. CT = CT_Cannot;
  764. else
  765. CT = canCalleeThrow(*this, E, CE->getCalleeDecl());
  766. if (CT == CT_Can)
  767. return CT;
  768. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  769. }
  770. case Expr::CXXConstructExprClass:
  771. case Expr::CXXTemporaryObjectExprClass: {
  772. CanThrowResult CT = canCalleeThrow(*this, E,
  773. cast<CXXConstructExpr>(E)->getConstructor());
  774. if (CT == CT_Can)
  775. return CT;
  776. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  777. }
  778. case Expr::LambdaExprClass: {
  779. const LambdaExpr *Lambda = cast<LambdaExpr>(E);
  780. CanThrowResult CT = CT_Cannot;
  781. for (LambdaExpr::capture_init_iterator Cap = Lambda->capture_init_begin(),
  782. CapEnd = Lambda->capture_init_end();
  783. Cap != CapEnd; ++Cap)
  784. CT = mergeCanThrow(CT, canThrow(*Cap));
  785. return CT;
  786. }
  787. case Expr::CXXNewExprClass: {
  788. CanThrowResult CT;
  789. if (E->isTypeDependent())
  790. CT = CT_Dependent;
  791. else
  792. CT = canCalleeThrow(*this, E, cast<CXXNewExpr>(E)->getOperatorNew());
  793. if (CT == CT_Can)
  794. return CT;
  795. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  796. }
  797. case Expr::CXXDeleteExprClass: {
  798. CanThrowResult CT;
  799. QualType DTy = cast<CXXDeleteExpr>(E)->getDestroyedType();
  800. if (DTy.isNull() || DTy->isDependentType()) {
  801. CT = CT_Dependent;
  802. } else {
  803. CT = canCalleeThrow(*this, E,
  804. cast<CXXDeleteExpr>(E)->getOperatorDelete());
  805. if (const RecordType *RT = DTy->getAs<RecordType>()) {
  806. const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
  807. CT = mergeCanThrow(CT, canCalleeThrow(*this, E, RD->getDestructor()));
  808. }
  809. if (CT == CT_Can)
  810. return CT;
  811. }
  812. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  813. }
  814. case Expr::CXXBindTemporaryExprClass: {
  815. // The bound temporary has to be destroyed again, which might throw.
  816. CanThrowResult CT = canCalleeThrow(*this, E,
  817. cast<CXXBindTemporaryExpr>(E)->getTemporary()->getDestructor());
  818. if (CT == CT_Can)
  819. return CT;
  820. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  821. }
  822. // ObjC message sends are like function calls, but never have exception
  823. // specs.
  824. case Expr::ObjCMessageExprClass:
  825. case Expr::ObjCPropertyRefExprClass:
  826. case Expr::ObjCSubscriptRefExprClass:
  827. return CT_Can;
  828. // All the ObjC literals that are implemented as calls are
  829. // potentially throwing unless we decide to close off that
  830. // possibility.
  831. case Expr::ObjCArrayLiteralClass:
  832. case Expr::ObjCDictionaryLiteralClass:
  833. case Expr::ObjCBoxedExprClass:
  834. return CT_Can;
  835. // Many other things have subexpressions, so we have to test those.
  836. // Some are simple:
  837. case Expr::ConditionalOperatorClass:
  838. case Expr::CompoundLiteralExprClass:
  839. case Expr::CXXConstCastExprClass:
  840. case Expr::CXXDefaultArgExprClass:
  841. case Expr::CXXReinterpretCastExprClass:
  842. case Expr::DesignatedInitExprClass:
  843. case Expr::ExprWithCleanupsClass:
  844. case Expr::ExtVectorElementExprClass:
  845. case Expr::InitListExprClass:
  846. case Expr::MemberExprClass:
  847. case Expr::ObjCIsaExprClass:
  848. case Expr::ObjCIvarRefExprClass:
  849. case Expr::ParenExprClass:
  850. case Expr::ParenListExprClass:
  851. case Expr::ShuffleVectorExprClass:
  852. case Expr::VAArgExprClass:
  853. return canSubExprsThrow(*this, E);
  854. // Some might be dependent for other reasons.
  855. case Expr::ArraySubscriptExprClass:
  856. case Expr::BinaryOperatorClass:
  857. case Expr::CompoundAssignOperatorClass:
  858. case Expr::CStyleCastExprClass:
  859. case Expr::CXXStaticCastExprClass:
  860. case Expr::CXXFunctionalCastExprClass:
  861. case Expr::ImplicitCastExprClass:
  862. case Expr::MaterializeTemporaryExprClass:
  863. case Expr::UnaryOperatorClass: {
  864. CanThrowResult CT = E->isTypeDependent() ? CT_Dependent : CT_Cannot;
  865. return mergeCanThrow(CT, canSubExprsThrow(*this, E));
  866. }
  867. // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms.
  868. case Expr::StmtExprClass:
  869. return CT_Can;
  870. case Expr::ChooseExprClass:
  871. if (E->isTypeDependent() || E->isValueDependent())
  872. return CT_Dependent;
  873. return canThrow(cast<ChooseExpr>(E)->getChosenSubExpr(Context));
  874. case Expr::GenericSelectionExprClass:
  875. if (cast<GenericSelectionExpr>(E)->isResultDependent())
  876. return CT_Dependent;
  877. return canThrow(cast<GenericSelectionExpr>(E)->getResultExpr());
  878. // Some expressions are always dependent.
  879. case Expr::CXXDependentScopeMemberExprClass:
  880. case Expr::CXXUnresolvedConstructExprClass:
  881. case Expr::DependentScopeDeclRefExprClass:
  882. return CT_Dependent;
  883. case Expr::AsTypeExprClass:
  884. case Expr::BinaryConditionalOperatorClass:
  885. case Expr::BlockExprClass:
  886. case Expr::CUDAKernelCallExprClass:
  887. case Expr::DeclRefExprClass:
  888. case Expr::ObjCBridgedCastExprClass:
  889. case Expr::ObjCIndirectCopyRestoreExprClass:
  890. case Expr::ObjCProtocolExprClass:
  891. case Expr::ObjCSelectorExprClass:
  892. case Expr::OffsetOfExprClass:
  893. case Expr::PackExpansionExprClass:
  894. case Expr::PseudoObjectExprClass:
  895. case Expr::SubstNonTypeTemplateParmExprClass:
  896. case Expr::SubstNonTypeTemplateParmPackExprClass:
  897. case Expr::UnaryExprOrTypeTraitExprClass:
  898. case Expr::UnresolvedLookupExprClass:
  899. case Expr::UnresolvedMemberExprClass:
  900. // FIXME: Can any of the above throw? If so, when?
  901. return CT_Cannot;
  902. case Expr::AddrLabelExprClass:
  903. case Expr::ArrayTypeTraitExprClass:
  904. case Expr::AtomicExprClass:
  905. case Expr::BinaryTypeTraitExprClass:
  906. case Expr::TypeTraitExprClass:
  907. case Expr::CXXBoolLiteralExprClass:
  908. case Expr::CXXNoexceptExprClass:
  909. case Expr::CXXNullPtrLiteralExprClass:
  910. case Expr::CXXPseudoDestructorExprClass:
  911. case Expr::CXXScalarValueInitExprClass:
  912. case Expr::CXXThisExprClass:
  913. case Expr::CXXUuidofExprClass:
  914. case Expr::CharacterLiteralClass:
  915. case Expr::ExpressionTraitExprClass:
  916. case Expr::FloatingLiteralClass:
  917. case Expr::GNUNullExprClass:
  918. case Expr::ImaginaryLiteralClass:
  919. case Expr::ImplicitValueInitExprClass:
  920. case Expr::IntegerLiteralClass:
  921. case Expr::ObjCEncodeExprClass:
  922. case Expr::ObjCStringLiteralClass:
  923. case Expr::ObjCBoolLiteralExprClass:
  924. case Expr::OpaqueValueExprClass:
  925. case Expr::PredefinedExprClass:
  926. case Expr::SizeOfPackExprClass:
  927. case Expr::StringLiteralClass:
  928. case Expr::UnaryTypeTraitExprClass:
  929. // These expressions can never throw.
  930. return CT_Cannot;
  931. #define STMT(CLASS, PARENT) case Expr::CLASS##Class:
  932. #define STMT_RANGE(Base, First, Last)
  933. #define LAST_STMT_RANGE(BASE, FIRST, LAST)
  934. #define EXPR(CLASS, PARENT)
  935. #define ABSTRACT_STMT(STMT)
  936. #include "clang/AST/StmtNodes.inc"
  937. case Expr::NoStmtClass:
  938. llvm_unreachable("Invalid class for expression");
  939. }
  940. llvm_unreachable("Bogus StmtClass");
  941. }
  942. } // end namespace clang