blob: 432e0172f66b5217c530d672b6ba6e102ab333c8 [file] [log] [blame]
Martin Brænne198ff492023-04-05 01:41:25 -07001// Part of the Crubit project, under the Apache License v2.0 with LLVM
2// Exceptions. See /LICENSE for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
Dmitri Gribenkoefc86642023-07-10 04:49:39 -07005#ifndef CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_ERROR_H_
6#define CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_ERROR_H_
Martin Brænne198ff492023-04-05 01:41:25 -07007
Dmitri Gribenkoa087d232023-07-10 08:03:46 -07008#include <string>
9#include <system_error>
10#include <utility>
11
Martin Brænne198ff492023-04-05 01:41:25 -070012#include "llvm/Support/Error.h"
Dmitri Gribenkoa087d232023-07-10 08:03:46 -070013#include "llvm/Support/raw_ostream.h"
Martin Brænne198ff492023-04-05 01:41:25 -070014
15namespace clang {
16namespace tidy {
17namespace lifetimes {
18
19// Error information for errors that originate in the `lifetime_analysis`
20// package.
21class LifetimeError : public llvm::ErrorInfo<LifetimeError> {
22 public:
23 enum class Type {
24 ElisionNotEnabled,
25 CannotElideOutputLifetimes,
26 Other,
27 };
28
29 LifetimeError(Type type, std::string message)
30 : type_(type), message_(std::move(message)) {}
31
32 Type type() const { return type_; }
33
34 void log(llvm::raw_ostream& OS) const override { OS << message_; }
35
36 std::error_code convertToErrorCode() const override {
37 return llvm::inconvertibleErrorCode();
38 }
39
40 static char ID;
41
42 private:
43 Type type_;
44 std::string message_;
45};
46
47} // namespace lifetimes
48} // namespace tidy
49} // namespace clang
50
Dmitri Gribenkoefc86642023-07-10 04:49:39 -070051#endif // CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_ERROR_H_