From: Craig Topper Date: Sat, 5 Dec 2015 07:41:44 +0000 (+0000) Subject: [AST] Use std::copy and std::fill to simplify some memcpy and memset calls. Also... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67d91667e29123383c1970cb6468bb5adec8cf07;p=clang [AST] Use std::copy and std::fill to simplify some memcpy and memset calls. Also const-correct some methods being used since the std::copy catches the mismatch where memcpy didn't. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254846 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 16dde19fda..1d1a99ed69 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -825,18 +825,20 @@ class AttributedStmt : public Stmt { AttributedStmt(SourceLocation Loc, ArrayRef Attrs, Stmt *SubStmt) : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), NumAttrs(Attrs.size()) { - memcpy(getAttrArrayPtr(), Attrs.data(), Attrs.size() * sizeof(Attr *)); + std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr()); } explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { - memset(getAttrArrayPtr(), 0, NumAttrs * sizeof(Attr *)); + std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr); } - Attr *const *getAttrArrayPtr() const { - return reinterpret_cast(this + 1); + const Attr *const *getAttrArrayPtr() const { + return reinterpret_cast(this + 1); + } + const Attr **getAttrArrayPtr() { + return reinterpret_cast(this + 1); } - Attr **getAttrArrayPtr() { return reinterpret_cast(this + 1); } public: static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,