This implements my suggestion to Lang.
llvm-svn: 264360
public:
MyError(std::string Msg) : Msg(Msg) {}
void log(OStream &OS) const override { OS << "MyError - " << Msg; }
+ static char ID;
private:
std::string Msg;
};
+ char MyError::ID = 0; // In MyError.cpp
+
Error bar() {
if (checkErrorCondition)
return make_error<MyError>("Error condition detected");
return ClassID == classID() || ParentErrT::isA(ClassID);
}
- static const void *classID() { return &ID; }
-
-private:
- static char ID;
+ static const void *classID() { return &ThisErrT::ID; }
};
-template <typename ThisErrT, typename ParentErrT>
-char ErrorInfo<ThisErrT, ParentErrT>::ID = 0;
-
/// Special ErrorInfo subclass representing a list of ErrorInfos.
/// Instances of this class are constructed by joinError.
class ErrorList final : public ErrorInfo<ErrorList> {
std::error_code convertToErrorCode() const override;
+ // Used by ErrorInfo::classID.
+ static char ID;
+
private:
ErrorList(std::unique_ptr<ErrorInfoBase> Payload1,
std::unique_ptr<ErrorInfoBase> Payload2) {
std::error_code convertToErrorCode() const override { return EC; }
void log(raw_ostream &OS) const override { OS << EC.message(); }
+ // Used by ErrorInfo::classID.
+ static char ID;
+
protected:
std::error_code EC;
};
void ErrorInfoBase::anchor() {}
char ErrorInfoBase::ID = 0;
-
-template <> char ErrorInfo<ErrorList>::ID = 0;
-template <> char ErrorInfo<ECError>::ID = 0;
+char ErrorList::ID = 0;
+char ECError::ID = 0;
static ManagedStatic<ErrorErrorCategory> ErrorErrorCat;
llvm_unreachable("CustomError doesn't support ECError conversion");
}
+ // Used by ErrorInfo::classID.
+ static char ID;
+
protected:
// This error is subclassed below, but we can't use inheriting constructors
// yet, so we can't propagate the constructors through ErrorInfo. Instead
int Info;
};
+char CustomError::ID = 0;
+
// Custom error class with a custom base class and some additional random
// 'info'.
class CustomSubError : public ErrorInfo<CustomSubError, CustomError> {
llvm_unreachable("CustomSubError doesn't support ECError conversion");
}
+ // Used by ErrorInfo::classID.
+ static char ID;
+
protected:
int ExtraInfo;
};
+char CustomSubError::ID = 0;
+
static Error handleCustomError(const CustomError &CE) { return Error(); }
static void handleCustomErrorVoid(const CustomError &CE) {}
}
} // end anon namespace
-
-template <> char ErrorInfo<CustomError>::ID = 0;
-template <> char ErrorInfo<CustomSubError, CustomError>::ID = 0;