Skip to content

Commit 3a12552

Browse files
committed
fixed all errors during build
1 parent ae9d4e4 commit 3a12552

File tree

11 files changed

+27
-25
lines changed

11 files changed

+27
-25
lines changed

include/up-cpp/utils/CallbackConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct [[nodiscard]] Connection {
173173
}
174174

175175
if constexpr (!std::is_void_v<RT>) {
176-
return result;
176+
return static_cast<std::optional<RT>>(std::move(result));
177177
}
178178
}
179179

include/up-cpp/utils/Expected.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ template <typename T, typename E>
5858
class Expected {
5959
public:
6060
constexpr explicit Expected(T arg) : storage_(std::forward<T>(arg)) {}
61-
constexpr explicit Expected(E arg) : storage_(std::forward<Unexpected<E>>(Unexpected<E>(arg))) {}
61+
//It E and T are the same type, this can cause problems. Previously, this was in use by implicid conversion
62+
// constexpr explicit Expected(E arg) : storage_(std::forward<Unexpected<E>>(Unexpected<E>(arg))) {}
63+
constexpr explicit Expected(Unexpected<E> arg) : storage_(std::forward<Unexpected<E>>(arg)) {}
6264

6365
constexpr Expected(const Expected&) = default;
6466
constexpr Expected(Expected&&) noexcept = default;

src/client/usubscription/v3/Consumer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Consumer::Consumer(std::shared_ptr<uprotocol::transport::UTransport> transport,
4343
if (status.code() == v1::UCode::OK) {
4444
return ConsumerOrStatus(std::move(consumer));
4545
}
46-
return ConsumerOrStatus(std::move(status));
46+
return ConsumerOrStatus(std::move(utils::Unexpected<v1::UStatus>(status)));
4747
}
4848
// If connection fails, return the error status.
49-
return ConsumerOrStatus(std::move(status));
49+
return ConsumerOrStatus(std::move(utils::Unexpected<v1::UStatus>(status)));
5050
}
5151

5252
v1::UStatus Consumer::createNotificationSink() {

src/communication/NotificationSink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ NotificationSink::SinkOrStatus NotificationSink::create(
4040
std::move(callback), source_filter, transport->getEntityUri());
4141

4242
if (!listener) {
43-
return SinkOrStatus(listener.error());
43+
return SinkOrStatus(utils::Unexpected<v1::UStatus>(listener.error()));
4444
}
4545

4646
return SinkOrStatus(std::make_unique<NotificationSink>(

src/communication/RpcClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ RpcClient::InvokeHandle RpcClient::invokeMethod(v1::UMessage&& request,
151151
status.set_message("Received response with !OK commstatus");
152152
std::call_once(*callback_once, [&callable,
153153
status = std::move(status)]() {
154-
callable(utils::Expected<v1::UMessage,v1::UStatus>(status));
154+
callable(utils::Expected<v1::UMessage,v1::UStatus>(utils::Unexpected<v1::UStatus>(status)));
155155
});
156156
}
157157
}
@@ -164,7 +164,7 @@ RpcClient::InvokeHandle RpcClient::invokeMethod(v1::UMessage&& request,
164164
auto expire = [callable, callback_once](v1::UStatus&& reason) mutable {
165165
std::call_once(
166166
*callback_once, [&callable, reason = std::move(reason)]() {
167-
callable(utils::Expected<v1::UMessage,v1::UStatus>(reason));
167+
callable(utils::Expected<v1::UMessage,v1::UStatus>(utils::Unexpected<v1::UStatus>(reason)));
168168
});
169169
};
170170
///////////////////////////////////////////////////////////////////////////

src/communication/RpcServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ RpcServer::ServerOrStatus RpcServer::create(
4343
v1::UStatus status;
4444
status.set_code(v1::UCode::INVALID_ARGUMENT);
4545
status.set_message("Invalid rpc URI");
46-
return ServerOrStatus(status);
46+
return ServerOrStatus(utils::Unexpected<v1::UStatus>(status));
4747
}
4848

4949
// Validate the payload format, if provided.
@@ -53,7 +53,7 @@ RpcServer::ServerOrStatus RpcServer::create(
5353
v1::UStatus status;
5454
status.set_code(v1::UCode::OUT_OF_RANGE);
5555
status.set_message("Invalid payload format");
56-
return ServerOrStatus(status);
56+
return ServerOrStatus(utils::Unexpected<v1::UStatus>(status));
5757
}
5858
}
5959

@@ -70,7 +70,7 @@ RpcServer::ServerOrStatus RpcServer::create(
7070
return ServerOrStatus(std::move(server));
7171
}
7272
// If connection fails, return the error status.
73-
return ServerOrStatus(std::move(status));
73+
return ServerOrStatus(std::move(utils::Unexpected<v1::UStatus>(status)));
7474
}
7575

7676
v1::UStatus RpcServer::connect(const v1::UUri& method, RpcCallback&& callback) {

src/communication/Subscriber.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace uri_validator = uprotocol::datamodel::validator::uri;
3737
auto handle = transport->registerListener(std::move(callback), topic);
3838

3939
if (!handle) {
40-
return SubscriberOrStatus(handle.error());
40+
return SubscriberOrStatus(utils::Unexpected<v1::UStatus>(handle.error()));
4141
}
4242

4343
return SubscriberOrStatus(std::make_unique<Subscriber>(

src/transport/UTransport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ UTransport::HandleOrStatus UTransport::registerListener(
9191
if (status.code() == v1::UCode::OK) {
9292
return HandleOrStatus(handle);
9393
}
94-
return HandleOrStatus(status);
94+
return HandleOrStatus(utils::Unexpected<v1::UStatus>(status));
9595
}
9696

9797
// NOTE: deprecated

test/coverage/communication/NotificationSinkTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class NotificationSinkTest : public testing::Test {
4545
static void SetUpTestSuite() {}
4646
static void TearDownTestSuite() {}
4747

48-
private:
4948
uprotocol::v1::UUri testTopicUUri_;
5049
uprotocol::v1::UUri testInvalidTopicUUri_;
5150
uprotocol::v1::UUri testDefaultSourceUUri_;

test/coverage/utils/ExpectedTest.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TEST_F(ExpectedTest, ExpectScalarScalar) {
5656

5757
TEST_F(ExpectedTest, UnexpectScalarScalar) {
5858
int sample = get_rand();
59-
auto expected = Expected<int, int>(Unexpected(sample));
59+
auto expected = Expected<int, int>(Unexpected<int>(sample));
6060
EXPECT_FALSE(bool(expected));
6161
EXPECT_FALSE(expected.has_value());
6262
EXPECT_EQ(sample, expected.error());
@@ -73,7 +73,7 @@ TEST_F(ExpectedTest, ExpectScalar) {
7373

7474
TEST_F(ExpectedTest, UnexpectScalar) {
7575
int sample = get_rand();
76-
auto expected = Expected<std::string, int>(Unexpected(sample));
76+
auto expected = Expected<std::string, int>(Unexpected<int>(sample));
7777
EXPECT_FALSE(bool(expected));
7878
EXPECT_FALSE(expected.has_value());
7979
EXPECT_EQ(sample, expected.error());
@@ -82,7 +82,7 @@ TEST_F(ExpectedTest, UnexpectScalar) {
8282
TEST_F(ExpectedTest, UnexpectValueOr) {
8383
int sample = get_rand();
8484
auto expected =
85-
Expected<int, std::string>(Unexpected(std::string("hello")));
85+
Expected<int, std::string>(Unexpected<std::string>(std::string("hello")));
8686
EXPECT_FALSE(bool(expected));
8787
EXPECT_FALSE(expected.has_value());
8888
EXPECT_EQ(sample, expected.value_or(sample));
@@ -111,7 +111,7 @@ TEST_F(ExpectedTest, UnexpectUnique) {
111111
auto x = get_rand();
112112
auto y = get_rand();
113113
auto expected = Expected<int, std::unique_ptr<Pair>>(
114-
Unexpected(std::make_unique<Pair>(x, y)));
114+
Unexpected<std::unique_ptr<Pair>>(std::make_unique<Pair>(x, y)));
115115
EXPECT_FALSE(bool(expected));
116116
EXPECT_FALSE(expected.has_value());
117117
auto p = std::move(expected).error();
@@ -136,7 +136,7 @@ TEST_F(ExpectedTest, UnexpectShared) {
136136
auto x = get_rand();
137137
auto y = get_rand();
138138
auto expected = Expected<int, std::shared_ptr<Pair>>(
139-
Unexpected(std::make_shared<Pair>(x, y)));
139+
Unexpected<std::shared_ptr<Pair>>(std::make_shared<Pair>(x, y)));
140140
EXPECT_FALSE(bool(expected));
141141
EXPECT_FALSE(expected.has_value());
142142
EXPECT_EQ(x, expected.error()->x);
@@ -158,7 +158,7 @@ TEST_F(ExpectedTest, ExpectStruct) {
158158
TEST_F(ExpectedTest, UnexpectStruct) {
159159
auto x = get_rand();
160160
auto y = get_rand();
161-
auto expected = Expected<int, Pair>(Unexpected(Pair(x, y)));
161+
auto expected = Expected<int, Pair>(Unexpected<Pair>(Pair(x, y)));
162162
EXPECT_FALSE(bool(expected));
163163
EXPECT_FALSE(expected.has_value());
164164
EXPECT_EQ(x, expected.error().x);
@@ -202,7 +202,7 @@ TEST_F(ExpectedTest, UnexpectStructDestruct) {
202202
auto x = get_rand();
203203
auto y = get_rand();
204204
auto expected =
205-
Expected<int, PairDestruct>(Unexpected(PairDestruct(x, y)));
205+
Expected<int, PairDestruct>(Unexpected<PairDestruct>(PairDestruct(x, y)));
206206
EXPECT_EQ(1, PairDestruct::cd_count);
207207
EXPECT_FALSE(bool(expected));
208208
EXPECT_FALSE(expected.has_value());
@@ -214,7 +214,7 @@ TEST_F(ExpectedTest, UnexpectStructDestruct) {
214214

215215
TEST_F(ExpectedTest, ExceptionValueCheckedWhenIsError) {
216216
auto expected =
217-
Expected<int, std::string>(Unexpected(std::string("hello")));
217+
Expected<int, std::string>(Unexpected<std::string>(std::string("hello")));
218218
EXPECT_THROW(
219219
{
220220
try {
@@ -249,7 +249,7 @@ TEST_F(ExpectedTest, ExceptionErrorCheckedWhenNotError) {
249249

250250
TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) {
251251
auto expected =
252-
Expected<const Pair, std::string>(Unexpected(std::string("hello")));
252+
Expected<const Pair, std::string>(Unexpected<std::string>(std::string("hello")));
253253
EXPECT_THROW(
254254
{
255255
try {
@@ -268,7 +268,7 @@ TEST_F(ExpectedTest, ExceptionDerefValueWhenUnexpected) {
268268

269269
TEST_F(ExpectedTest, ExceptionDerefPtrWhenUnexpected) {
270270
auto expected =
271-
Expected<Pair, std::string>(Unexpected(std::string("hello")));
271+
Expected<Pair, std::string>(Unexpected<std::string>(std::string("hello")));
272272
EXPECT_THROW(
273273
{
274274
try {

0 commit comments

Comments
 (0)