[PATCH] D62116: [Sema] raise nullptr check to cover additional uses

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 19 19:11:20 PDT 2019


nickdesaulniers created this revision.
nickdesaulniers added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was flagged in https://www.viva64.com/en/b/0629/ under "Snippet No.
14" (see under #13). It looks like PVS studio flags nullptr checks where
the ptr is used inbetween creation and checking against nullptr.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62116

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -551,11 +551,12 @@
       LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New));
     } else {
       // Allow 'this' within late-parsed attributes.
-      NamedDecl *ND = dyn_cast<NamedDecl>(New);
-      CXXRecordDecl *ThisContext =
-          dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
-      CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
-                                 ND && ND->isCXXInstanceMember());
+      if (NamedDecl *ND = dyn_cast<NamedDecl>(New)) {
+        CXXRecordDecl *ThisContext =
+            dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
+        CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
+                                   ND->isCXXInstanceMember());
+      }
 
       Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context,
                                                          *this, TemplateArgs);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62116.200196.patch
Type: text/x-patch
Size: 1142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190520/3e4cc90f/attachment-0001.bin>


More information about the cfe-commits mailing list