From 3d1f884c56ab3d043c9605284b11b8f36acfba17 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 8 Oct 2017 20:53:36 +0000 Subject: [PATCH] Make SourceLocation, QualType and friends have constexpr constructors. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315194 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/CharUnits.h | 4 ++-- include/clang/AST/Type.h | 6 ++---- include/clang/Basic/SourceLocation.h | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/clang/AST/CharUnits.h b/include/clang/AST/CharUnits.h index 564c8ec9b9..ddead6046a 100644 --- a/include/clang/AST/CharUnits.h +++ b/include/clang/AST/CharUnits.h @@ -40,14 +40,14 @@ namespace clang { typedef int64_t QuantityType; private: - QuantityType Quantity; + QuantityType Quantity = 0; explicit CharUnits(QuantityType C) : Quantity(C) {} public: /// CharUnits - A default constructor. - CharUnits() : Quantity(0) {} + CharUnits() = default; /// Zero - Construct a CharUnits quantity of zero. static CharUnits Zero() { diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 52a1ff8bd2..2b94772fa3 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -162,8 +162,6 @@ public: FastMask = (1 << FastWidth) - 1 }; - Qualifiers() : Mask(0) {} - /// Returns the common set of qualifiers while removing them from /// the given sets. static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) { @@ -539,7 +537,7 @@ private: // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31| // |C R V|U|GCAttr|Lifetime|AddressSpace| - uint32_t Mask; + uint32_t Mask = 0; static const uint32_t UMask = 0x8; static const uint32_t UShift = 3; @@ -634,7 +632,7 @@ class QualType { friend class QualifierCollector; public: - QualType() {} + QualType() = default; QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {} diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index 991cb78695..7418b50f9d 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -39,10 +39,9 @@ class SourceManager; class FileID { /// \brief A mostly-opaque identifier, where 0 is "invalid", >0 is /// this module, and <-1 is something loaded from another module. - int ID; -public: - FileID() : ID(0) {} + int ID = 0; +public: bool isValid() const { return ID != 0; } bool isInvalid() const { return ID == 0; } @@ -86,17 +85,15 @@ private: /// /// It is important that this type remains small. It is currently 32 bits wide. class SourceLocation { - unsigned ID; + unsigned ID = 0; friend class SourceManager; friend class ASTReader; friend class ASTWriter; enum : unsigned { MacroIDBit = 1U << 31 }; -public: - - SourceLocation() : ID(0) {} +public: bool isFileID() const { return (ID & MacroIDBit) == 0; } bool isMacroID() const { return (ID & MacroIDBit) != 0; } @@ -198,8 +195,9 @@ inline bool operator<(const SourceLocation &LHS, const SourceLocation &RHS) { class SourceRange { SourceLocation B; SourceLocation E; + public: - SourceRange(): B(SourceLocation()), E(SourceLocation()) {} + SourceRange() = default; SourceRange(SourceLocation loc) : B(loc), E(loc) {} SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {} @@ -230,9 +228,10 @@ public: /// range. class CharSourceRange { SourceRange Range; - bool IsTokenRange; + bool IsTokenRange = false; + public: - CharSourceRange() : IsTokenRange(false) {} + CharSourceRange() = default; CharSourceRange(SourceRange R, bool ITR) : Range(R), IsTokenRange(ITR) {} static CharSourceRange getTokenRange(SourceRange R) { @@ -330,10 +329,11 @@ class FileEntry; /// /// This is useful for argument passing to functions that expect both objects. class FullSourceLoc : public SourceLocation { - const SourceManager *SrcMgr; + const SourceManager *SrcMgr = nullptr; + public: /// \brief Creates a FullSourceLoc where isValid() returns \c false. - explicit FullSourceLoc() : SrcMgr(nullptr) {} + FullSourceLoc() = default; explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM) : SourceLocation(Loc), SrcMgr(&SM) {} -- 2.40.0