Since `StringRef::empty` can be used in constexpr context, it seems reasonable that `SMLoc::isValid` should be too. The default-ctor and `operator==` are made constexpr for consistency.
In particular, the `constexpr` keyword is needed for silencing warnings on Windows (whereas Linux allows constexpr usage without the keyword).
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D154741
const char *Ptr = nullptr;
public:
- SMLoc() = default;
+ constexpr SMLoc() = default;
- bool isValid() const { return Ptr != nullptr; }
+ constexpr bool isValid() const { return Ptr != nullptr; }
- bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
- bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
+ constexpr bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
+ constexpr bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
- const char *getPointer() const { return Ptr; }
+ constexpr const char *getPointer() const { return Ptr; }
static SMLoc getFromPointer(const char *Ptr) {
SMLoc L;
std::optional<Var::Num> n = {})
: name(name), loc(loc), id(id), num(n), kind(vk) {
assert(!name.empty() && "null StringRef");
+ assert(loc.isValid() && "null SMLoc");
assert(isWF(vk) && "unknown VarKind");
assert((!n || Var::isWF_Num(*n)) && "Var::Num is too large");
- // NOTE TO Wren: windows did not like loc.isValid constexpr
}
constexpr StringRef getName() const { return name; }