[PATCH] D140598: [Clang] Add sanity check in Sema::getDestructorName to prevent nullptr dereference

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 5 13:39:30 PST 2023


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaExprCXX.cpp:393
     // reasonably apply this fallback for dependent nested-name-specifiers.
-    if (SS.getScopeRep()->getPrefix()) {
+    if (SS.isSet() && SS.getScopeRep()->getPrefix()) {
       if (ParsedType T = LookupInScope()) {
----------------
tahonermann wrote:
> `CXXScopeSpec::isSet()` is apparently (intended to be) deprecated.
> ```
> clang/include/clang/Sema/DeclSpec.h:
>  209   /// Deprecated.  Some call sites intend isNotEmpty() while others intend
>  210   /// isValid().
>  211   bool isSet() const { return getScopeRep() != nullptr; }
> ```
> It sounds like this should instead call `.isValid()` or `.isNotEmpty()`, but I'm not sure which.
We want to use `isValid()` -- `isNotEmpty()` will return `true` when the scope spec is present but invalid, so the call to `SS.getScopeRep()->getPrefix()` would crash in that case.


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

https://reviews.llvm.org/D140598



More information about the cfe-commits mailing list