r315194 - Make SourceLocation, QualType and friends have constexpr constructors.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 8 13:53:36 PDT 2017


Author: d0k
Date: Sun Oct  8 13:53:36 2017
New Revision: 315194

URL: http://llvm.org/viewvc/llvm-project?rev=315194&view=rev
Log:
Make SourceLocation, QualType and friends have constexpr constructors.

No functionality change intended.

Modified:
    cfe/trunk/include/clang/AST/CharUnits.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/include/clang/Basic/SourceLocation.h

Modified: cfe/trunk/include/clang/AST/CharUnits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=315194&r1=315193&r2=315194&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CharUnits.h (original)
+++ cfe/trunk/include/clang/AST/CharUnits.h Sun Oct  8 13:53:36 2017
@@ -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() {

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=315194&r1=315193&r2=315194&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Oct  8 13:53:36 2017
@@ -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) {}

Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=315194&r1=315193&r2=315194&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Sun Oct  8 13:53:36 2017
@@ -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 SourceLocati
 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) {}




More information about the cfe-commits mailing list