[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 23 04:26:17 PDT 2021


aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

Thanks for the cleanup! Btw, it's helpful if you add more context to the patch when generating the diff. I typically use `git diff -U9999` when generating a diff as that gives plenty of context for the patch review within Phabricator.



================
Comment at: clang/lib/Sema/SemaConcept.cpp:1065-1068
   assert(TC &&
          "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
+      cast<ConceptSpecializationExpr>(TC->getImmediatelyDeclaredConstraint());
----------------
If we're going to be touching this code, there's more suspect code here that needs to be cleaned up a bit. Directly above this is:
```
  const TypeConstraint *TC =
      cast<TemplateTypeParmDecl>(TPL->getParam(0))->getTypeConstraint();
  assert(TC &&
         "TPL must have a template type parameter with a type constraint");
```
That assertion can be removed entirely -- if the `cast<>` fails, it doesn't return null, it asserts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108481/new/

https://reviews.llvm.org/D108481



More information about the cfe-commits mailing list