Skip to content

Commit 6ee03fd

Browse files
committed
Fix CI for c++14 build
1 parent 9e7d107 commit 6ee03fd

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

.github/workflows/kafka_api_ci_tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
OS_VERSION: ${{ matrix.os }}
1717
BUILD_CXX: ${{ matrix.build-cxx }}
1818
BUILD_TYPE: ${{ matrix.build-type }}
19-
CXX_VERSION: ${{ matrix.cxx-version }}
19+
CXX_STANDARD: ${{ matrix.cxx-standard }}
2020
CHECK_OPTION: ${{ matrix.check-option }}
2121
GENERATE_DOC: ${{ matrix.generate-doc }}
2222
WITH_INSTALLATION: ${{ matrix.with-installation }}
@@ -38,7 +38,7 @@ jobs:
3838
- os: ubuntu-20.04
3939
build-cxx: g++
4040
build-type: Release
41-
cxx-version: c++14
41+
cxx-standard: 14
4242

4343
- os: ubuntu-20.04
4444
build-cxx: g++
@@ -134,8 +134,8 @@ jobs:
134134
run: |
135135
cd ${BUILD_SUB_DIR}
136136
137-
if [ ${CXX_VERSION} ]; then
138-
export CMAKE_CXX_FLAGS="-DCMAKE_CXX_FLAGS=\"-std=${CXX_VERSION}\""
137+
if [ ${CXX_STANDARD} ]; then
138+
export CMAKE_CXX_STANDARD="-DCMAKE_CXX_STANDARD=${CXX_STANDARD}"
139139
fi
140140
141141
if [ ${BUILD_TYPE} ]; then
@@ -164,7 +164,7 @@ jobs:
164164
export BUILD_OPTION="${BUILD_OPTION} -DBUILD_OPTION_GEN_DOC=ON"
165165
fi
166166
167-
env CXX=${BUILD_CXX} cmake ../.. ${CMAKE_CXX_FLAGS} ${CMAKE_BUILD_TYPE} ${BUILD_OPTION}
167+
env CXX=${BUILD_CXX} cmake ../.. ${CMAKE_CXX_STANDARD} ${CMAKE_BUILD_TYPE} ${BUILD_OPTION}
168168
169169
- name: Build
170170
run: |

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ include(CMakePushCheckState)
1010
#---------------------------
1111
# Suggest to use C++17
1212
#---------------------------
13-
set(CMAKE_CXX_STANDARD 17)
13+
if (NOT CMAKE_CXX_STANDARD)
14+
set(CMAKE_CXX_STANDARD 17)
15+
endif ()
1416
set(CMAKE_CXX_STANDARD_REQUIRED False)
1517

1618
add_compile_options("-Wall" "-Werror" "-Wextra" "-Wshadow" "-Wno-unused-result")

include/kafka/Error.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ class Error
7777
/**
7878
* Obtains the underlying error code.
7979
*/
80-
virtual std::error_code errorCode() const { return ErrorCode(rd_kafka_error_code(_rkError.get())); }
80+
virtual std::error_code errorCode() const { return ErrorCode(rd_kafka_error_code(_rkError.get())); }
8181

8282
/**
8383
* Readable error string.
8484
*/
85-
virtual std::string message() const { return rd_kafka_error_string(_rkError.get()); }
85+
virtual std::string message() const { return rd_kafka_error_string(_rkError.get()); }
8686

8787
/**
8888
* Fatal error indicates that the client instance is no longer usable.
8989
*/
90-
virtual std::optional<bool> isFatal() const { return rd_kafka_error_is_fatal(_rkError.get()); }
90+
virtual Optional<bool> isFatal() const { return rd_kafka_error_is_fatal(_rkError.get()); }
9191

9292
/**
9393
* Show whether the operation may be retried.
9494
*/
95-
virtual std::optional<bool> isRetriable() const { return rd_kafka_error_is_retriable(_rkError.get()); }
95+
virtual Optional<bool> isRetriable() const { return rd_kafka_error_is_retriable(_rkError.get()); }
9696

9797
private:
9898
rd_kafka_error_shared_ptr _rkError;
@@ -107,10 +107,10 @@ class SimpleError: public Error
107107
explicit SimpleError(rd_kafka_resp_err_t respErr, std::string message): _respErr(respErr), _message(std::move(message)) {}
108108
SimpleError(const SimpleError&) = default;
109109

110-
std::error_code errorCode() const override { return ErrorCode(_respErr); }
111-
std::string message() const override { return _message; }
112-
std::optional<bool> isFatal() const override { return {}; }
113-
std::optional<bool> isRetriable() const override { return {}; }
110+
std::error_code errorCode() const override { return ErrorCode(_respErr); }
111+
std::string message() const override { return _message; }
112+
Optional<bool> isFatal() const override { return {}; }
113+
Optional<bool> isRetriable() const override { return {}; }
114114

115115
private:
116116
rd_kafka_resp_err_t _respErr;

include/kafka/KafkaException.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class KafkaException: public std::exception
2525
: _when(std::chrono::system_clock::now()),
2626
_filename(filename),
2727
_lineno(lineno),
28-
_error(std::make_unique<SimpleError>(respErr, errMsg))
28+
_error(std::make_shared<SimpleError>(respErr, errMsg))
2929
{}
3030

3131
KafkaException(const char* filename, std::size_t lineno, rd_kafka_resp_err_t respErr)
@@ -36,7 +36,7 @@ class KafkaException: public std::exception
3636
: _when(std::chrono::system_clock::now()),
3737
_filename(filename),
3838
_lineno(lineno),
39-
_error(std::make_unique<Error>(error))
39+
_error(std::make_shared<Error>(error))
4040
{}
4141

4242
/**
@@ -60,7 +60,7 @@ class KafkaException: public std::exception
6060
const TimePoint _when;
6161
const std::string _filename;
6262
const std::size_t _lineno;
63-
const std::unique_ptr<Error> _error;
63+
const std::shared_ptr<Error> _error;
6464
mutable std::string _what;
6565
};
6666

include/kafka/KafkaProducer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ KafkaProducer::sendMessage(const ProducerRecord& record,
294294
RD_KAFKA_V_MSGFLAGS(msgFlags),
295295
RD_KAFKA_V_HEADERS(hdrs),
296296
RD_KAFKA_V_VALUE(const_cast<void*>(valuePtr), valueLen), // NOLINT
297-
RD_KAFKA_V_KEY(keyPtr, keyLen),
297+
RD_KAFKA_V_KEY(keyPtr, keyLen), // NOLINT
298298
RD_KAFKA_V_OPAQUE(opaquePtr),
299299
RD_KAFKA_V_END);
300300
#pragma GCC diagnostic pop
@@ -312,7 +312,7 @@ KafkaProducer::sendMessage(const ProducerRecord& record,
312312
RD_KAFKA_V_PARTITION(partition),
313313
RD_KAFKA_V_MSGFLAGS(msgFlags),
314314
RD_KAFKA_V_VALUE(const_cast<void*>(valuePtr), valueLen), // NOLINT
315-
RD_KAFKA_V_KEY(keyPtr, keyLen),
315+
RD_KAFKA_V_KEY(keyPtr, keyLen), // NOLINT
316316
RD_KAFKA_V_OPAQUE(opaquePtr),
317317
RD_KAFKA_V_END);
318318
#pragma GCC diagnostic pop

tests/integration/TestKafkaConsumer.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,11 +1476,17 @@ TEST(KafkaManualCommitConsumer, OffsetsForTime)
14761476

14771477
auto metadata1 = producer.send(Kafka::ProducerRecord(topic1, partition1, Kafka::NullKey, Kafka::NullValue));
14781478
std::cout << "[" << Utility::getCurrentTime() << "] Just send a message, metadata: " << metadata1.toString() << std::endl;
1479-
expected[{topic1, partition1}] = *metadata1.offset();
1479+
if (auto offset = metadata1.offset())
1480+
{
1481+
expected[{topic1, partition1}] = *offset;
1482+
}
14801483

14811484
auto metadata2 = producer.send(Kafka::ProducerRecord(topic2, partition2, Kafka::NullKey, Kafka::NullValue));
14821485
std::cout << "[" << Utility::getCurrentTime() << "] Just send a message, metadata: " << metadata2.toString() << std::endl;
1483-
expected[{topic2, partition2}] = *metadata2.offset();
1486+
if (auto offset = metadata2.offset())
1487+
{
1488+
expected[{topic2, partition2}] = *offset;
1489+
}
14841490

14851491
expectedOffsets.emplace_back(expected);
14861492

0 commit comments

Comments
 (0)