Author: Timm Bäder Date: 2023-09-05T12:35:06+02:00 New Revision: fde2b0d6dba709ee6d699a4d67657604b8c0a026
URL: https://github.com/llvm/llvm-project/commit/fde2b0d6dba709ee6d699a4d67657604b8c0a026 DIFF: https://github.com/llvm/llvm-project/commit/fde2b0d6dba709ee6d699a4d67657604b8c0a026.diff LOG: [clang][Interp][NFC] Add [[nodiscard]] to a few Pointer methods These methods are all const and return a new Pointer instance instead of modifying the given instance. Added: Modified: clang/lib/AST/Interp/Pointer.h Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h index f2d8922f896552..3834237f11d131 100644 --- a/clang/lib/AST/Interp/Pointer.h +++ b/clang/lib/AST/Interp/Pointer.h @@ -92,7 +92,7 @@ class Pointer { APValue toRValue(const Context &Ctx) const; /// Offsets a pointer inside an array. - Pointer atIndex(unsigned Idx) const { + [[nodiscard]] Pointer atIndex(unsigned Idx) const { if (Base == RootPtrMark) return Pointer(Pointee, RootPtrMark, getDeclDesc()->getSize()); unsigned Off = Idx * elemSize(); @@ -104,21 +104,21 @@ class Pointer { } /// Creates a pointer to a field. - Pointer atField(unsigned Off) const { + [[nodiscard]] Pointer atField(unsigned Off) const { unsigned Field = Offset + Off; return Pointer(Pointee, Field, Field); } /// Subtract the given offset from the current Base and Offset /// of the pointer. - Pointer atFieldSub(unsigned Off) const { + [[nodiscard]] Pointer atFieldSub(unsigned Off) const { assert(Offset >= Off); unsigned O = Offset - Off; return Pointer(Pointee, O, O); } /// Restricts the scope of an array element pointer. - Pointer narrow() const { + [[nodiscard]] Pointer narrow() const { // Null pointers cannot be narrowed. if (isZero() || isUnknownSizeArray()) return *this; @@ -154,7 +154,7 @@ class Pointer { } /// Expands a pointer to the containing array, undoing narrowing. - Pointer expand() const { + [[nodiscard]] Pointer expand() const { if (isElementPastEnd()) { // Revert to an outer one-past-end pointer. unsigned Adjust; @@ -193,7 +193,7 @@ class Pointer { SourceLocation getDeclLoc() const { return getDeclDesc()->getLocation(); } /// Returns a pointer to the object of which this pointer is a field. - Pointer getBase() const { + [[nodiscard]] Pointer getBase() const { if (Base == RootPtrMark) { assert(Offset == PastEndMark && "cannot get base of a block"); return Pointer(Pointee, Base, 0); @@ -203,7 +203,7 @@ class Pointer { return Pointer(Pointee, NewBase, NewBase); } /// Returns the parent array. - Pointer getArray() const { + [[nodiscard]] Pointer getArray() const { if (Base == RootPtrMark) { assert(Offset != 0 && Offset != PastEndMark && "not an array element"); return Pointer(Pointee, Base, 0); @@ -226,7 +226,7 @@ class Pointer { return getFieldDesc()->getType(); } - Pointer getDeclPtr() const { return Pointer(Pointee); } + [[nodiscard]] Pointer getDeclPtr() const { return Pointer(Pointee); } /// Returns the element size of the innermost field. size_t elemSize() const { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits