Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Upgrade to clang-format 18 #2684

Merged
merged 9 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ jobs:

format:
name: Format
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: setup
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Increment the:
* [SDK] Update ExemplarFilter and ExemplarReservoir for spec
[#2372](https://github.com/open-telemetry/opentelemetry-cpp/pull/2372)

* [CI] Upgrade to clang-format 18
[#2684](https://github.com/open-telemetry/opentelemetry-cpp/pull/2684)

Notes on experimental features:

* [#2372](https://github.com/open-telemetry/opentelemetry-cpp/issues/2372)
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/common/kv_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class KeyValueProperties
}

// Move contructor and assignment operator
Entry(Entry &&other) = default;
Entry(Entry &&other) = default;
Entry &operator=(Entry &&other) = default;

// Creates an Entry for a given key-value pair.
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/common/spin_lock_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class SpinLockMutex
{
public:
SpinLockMutex() noexcept {}
~SpinLockMutex() noexcept = default;
SpinLockMutex(const SpinLockMutex &) = delete;
~SpinLockMutex() noexcept = default;
SpinLockMutex(const SpinLockMutex &) = delete;
SpinLockMutex &operator=(const SpinLockMutex &) = delete;

static inline void fast_yield() noexcept
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/logs/event_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EventLogger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void EmitEvent(nostd::string_view event_name, ArgumentType &&... args)
void EmitEvent(nostd::string_view event_name, ArgumentType &&...args)
{
nostd::shared_ptr<Logger> delegate_logger = GetDelegateLogger();
if (!delegate_logger)
Expand Down
16 changes: 8 additions & 8 deletions api/include/opentelemetry/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void EmitLogRecord(nostd::unique_ptr<LogRecord> &&log_record, ArgumentType &&... args)
void EmitLogRecord(nostd::unique_ptr<LogRecord> &&log_record, ArgumentType &&...args)
{
if (!log_record)
{
Expand Down Expand Up @@ -97,7 +97,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void EmitLogRecord(ArgumentType &&... args)
void EmitLogRecord(ArgumentType &&...args)
{
nostd::unique_ptr<LogRecord> log_record = CreateLogRecord();

Expand All @@ -120,7 +120,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void Trace(ArgumentType &&... args) noexcept
void Trace(ArgumentType &&...args) noexcept
{
static_assert(
!detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
Expand All @@ -144,7 +144,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void Debug(ArgumentType &&... args) noexcept
void Debug(ArgumentType &&...args) noexcept
{
static_assert(
!detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
Expand All @@ -168,7 +168,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void Info(ArgumentType &&... args) noexcept
void Info(ArgumentType &&...args) noexcept
{
static_assert(
!detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
Expand All @@ -192,7 +192,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void Warn(ArgumentType &&... args) noexcept
void Warn(ArgumentType &&...args) noexcept
{
static_assert(
!detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
Expand All @@ -216,7 +216,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void Error(ArgumentType &&... args) noexcept
void Error(ArgumentType &&...args) noexcept
{
static_assert(
!detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
Expand All @@ -240,7 +240,7 @@ class Logger
* span<pair<string_view, AttributeValue>> -> attributes(return type of MakeAttributes)
*/
template <class... ArgumentType>
void Fatal(ArgumentType &&... args) noexcept
void Fatal(ArgumentType &&...args) noexcept
{
static_assert(
!detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/logs/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class OPENTELEMETRY_EXPORT Provider
return provider;
}

OPENTELEMETRY_API_SINGLETON static nostd::shared_ptr<EventLoggerProvider>
&GetEventProvider() noexcept
OPENTELEMETRY_API_SINGLETON static nostd::shared_ptr<EventLoggerProvider> &
GetEventProvider() noexcept
{
static nostd::shared_ptr<EventLoggerProvider> provider(new NoopEventLoggerProvider);
return provider;
Expand Down
7 changes: 5 additions & 2 deletions api/include/opentelemetry/nostd/detail/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

#include "opentelemetry/version.h"

#define OPENTELEMETRY_RETURN(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { return __VA_ARGS__; }
#define OPENTELEMETRY_RETURN(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) \
{ \
return __VA_ARGS__; \
}

OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
Expand Down
32 changes: 18 additions & 14 deletions api/include/opentelemetry/nostd/detail/invoke.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#include "opentelemetry/nostd/detail/void.h"
#include "opentelemetry/version.h"

#define OPENTELEMETRY_RETURN(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { return __VA_ARGS__; }
#define OPENTELEMETRY_RETURN(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) \
{ \
return __VA_ARGS__; \
}

OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
Expand All @@ -34,23 +37,23 @@ template <>
struct Invoke<true /* pmf */, 0 /* is_base_of */>
{
template <typename R, typename T, typename Arg, typename... Args>
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&...args)
OPENTELEMETRY_RETURN((std::forward<Arg>(arg).*pmf)(std::forward<Args>(args)...))
};

template <>
struct Invoke<true /* pmf */, 1 /* is_reference_wrapper */>
{
template <typename R, typename T, typename Arg, typename... Args>
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&...args)
OPENTELEMETRY_RETURN((std::forward<Arg>(arg).get().*pmf)(std::forward<Args>(args)...))
};

template <>
struct Invoke<true /* pmf */, 2 /* otherwise */>
{
template <typename R, typename T, typename Arg, typename... Args>
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&...args)
OPENTELEMETRY_RETURN(((*std::forward<Arg>(arg)).*pmf)(std::forward<Args>(args)...))
};

Expand Down Expand Up @@ -79,20 +82,21 @@ struct Invoke<false /* pmo */, 2 /* otherwise */>
};

template <typename R, typename T, typename Arg, typename... Args>
inline constexpr auto invoke_impl(R T::*f, Arg &&arg, Args &&... args)
OPENTELEMETRY_RETURN(Invoke<std::is_function<R>::value,
(std::is_base_of<T, decay_t<Arg>>::value
? 0
: is_reference_wrapper<decay_t<Arg>>::value ? 1 : 2)>::
invoke(f, std::forward<Arg>(arg), std::forward<Args>(args)...))
inline constexpr auto invoke_impl(R T::*f, Arg &&arg, Args &&...args) OPENTELEMETRY_RETURN(
Invoke<std::is_function<R>::value,
(std::is_base_of<T, decay_t<Arg>>::value ? 0
: is_reference_wrapper<decay_t<Arg>>::value ? 1
: 2)>::invoke(f,
std::forward<Arg>(arg),
std::forward<Args>(args)...))

#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4100)
#endif
template <typename F, typename... Args>
inline constexpr auto invoke_impl(F &&f, Args &&... args)
OPENTELEMETRY_RETURN(std::forward<F>(f)(std::forward<Args>(args)...))
template <typename F, typename... Args>
inline constexpr auto invoke_impl(F &&f, Args &&...args)
OPENTELEMETRY_RETURN(std::forward<F>(f)(std::forward<Args>(args)...))
#ifdef _MSC_VER
# pragma warning(pop)
#endif
Expand Down
6 changes: 3 additions & 3 deletions api/include/opentelemetry/nostd/detail/trait.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ template <typename T,
class IsAvailable>
inline constexpr Trait trait()
{
return IsTriviallyAvailable<T>::value
? Trait::TriviallyAvailable
: IsAvailable<T>::value ? Trait::Available : Trait::Unavailable;
return IsTriviallyAvailable<T>::value ? Trait::TriviallyAvailable
: IsAvailable<T>::value ? Trait::Available
: Trait::Unavailable;
}

inline constexpr Trait common_trait_impl(Trait result)
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/nostd/unique_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class unique_ptr
return *this;
}

operator std::unique_ptr<T>() &&noexcept { return std::unique_ptr<T>{release()}; }
operator std::unique_ptr<T>() && noexcept { return std::unique_ptr<T>{release()}; }

operator bool() const noexcept { return ptr_ != nullptr; }

Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/nostd/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
}

template <class T, size_t N>
size_t size(T (&/* array */)[N]) noexcept
size_t size(T (& /* array */)[N]) noexcept
{
return N;
}
Expand Down
14 changes: 7 additions & 7 deletions api/include/opentelemetry/plugin/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* library and a dynamically loaded plugin. The weak linkage allows for multiple implementations to
* be linked in without getting multiple definition errors.
*/
# define OPENTELEMETRY_DEFINE_PLUGIN_HOOK(X) \
extern "C" { \
extern __declspec(dllexport) \
opentelemetry::plugin::OpenTelemetryHook const OpenTelemetryMakeFactoryImpl; \
\
__declspec(selectany) \
opentelemetry::plugin::OpenTelemetryHook const OpenTelemetryMakeFactoryImpl = X; \
# define OPENTELEMETRY_DEFINE_PLUGIN_HOOK(X) \
extern "C" { \
extern __declspec(dllexport) opentelemetry::plugin::OpenTelemetryHook const \
OpenTelemetryMakeFactoryImpl; \
\
__declspec(selectany) opentelemetry::plugin::OpenTelemetryHook const \
OpenTelemetryMakeFactoryImpl = X; \
} // extern "C"

#else
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/std/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
}

template <class T, std::size_t N>
std::size_t size(T (&/* array */)[N]) noexcept
std::size_t size(T (& /* array */)[N]) noexcept
{
return N;
}
Expand Down
10 changes: 4 additions & 6 deletions api/include/opentelemetry/std/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class bad_variant_access : public std::exception
// nostd::get<...> for Apple Clang
//
template <typename T, class... Types>
constexpr auto get_type = [](auto &&t) constexpr -> decltype(auto)
{
constexpr auto get_type = [](auto &&t) constexpr -> decltype(auto) {
auto v = t;
auto result = std::get_if<T>(&v); // TODO: optimize with std::forward(t) if t is not rvalue
if (result)
Expand All @@ -69,8 +68,7 @@ constexpr auto get_type = [](auto &&t) constexpr -> decltype(auto)
};

template <std::size_t I, class... Types>
constexpr auto get_index = [](auto &&t) constexpr -> decltype(auto)
{
constexpr auto get_index = [](auto &&t) constexpr -> decltype(auto) {
auto v = t;
auto result = std::get_if<I>(&v); // TODO: optimize with std::forward(t) if t is not rvalue
if (result)
Expand Down Expand Up @@ -132,7 +130,7 @@ constexpr const T &&get(const std::variant<Types...> &&v)
};

template <class _Callable, class... _Variants>
constexpr auto visit(_Callable &&_Obj, _Variants &&... _Args)
constexpr auto visit(_Callable &&_Obj, _Variants &&..._Args)
{
// Ref:
// https://stackoverflow.com/questions/52310835/xcode-10-call-to-unavailable-function-stdvisit
Expand Down Expand Up @@ -193,7 +191,7 @@ constexpr const T &&get(const std::variant<Types...> &&v)
}

template <class _Callable, class... _Variants>
constexpr auto visit(_Callable &&_Obj, _Variants &&... _Args)
constexpr auto visit(_Callable &&_Obj, _Variants &&..._Args)
{
return std::visit<_Callable, _Variants...>(static_cast<_Callable &&>(_Obj),
static_cast<_Variants &&>(_Args)...);
Expand Down
6 changes: 3 additions & 3 deletions api/include/opentelemetry/trace/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class Span
virtual ~Span() = default;

// Not copiable or movable.
Span(const Span &) = delete;
Span(Span &&) = delete;
Span(const Span &) = delete;
Span(Span &&) = delete;
Span &operator=(const Span &) = delete;
Span &operator=(Span &&) = delete;
Span &operator=(Span &&) = delete;

/**
* Sets an attribute on the Span (ABI).
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Tracer
template <class T,
class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr,
nostd::enable_if_t<detail::is_span_context_kv_iterable<U>::value> * = nullptr>
nostd::enable_if_t<detail::is_span_context_kv_iterable<U>::value> * = nullptr>
nostd::shared_ptr<Span> StartSpan(nostd::string_view name,
const T &attributes,
const U &links,
Expand Down
3 changes: 1 addition & 2 deletions api/test/common/spinlock_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ inline void SpinThrash(benchmark::State &s, SpinLockType &spinlock, LockF lock,
static void BM_SpinLockThrashing(benchmark::State &s)
{
SpinLockMutex spinlock;
SpinThrash(
s, spinlock, [](SpinLockMutex &m) { m.lock(); }, [](SpinLockMutex &m) { m.unlock(); });
SpinThrash(s, spinlock, [](SpinLockMutex &m) { m.lock(); }, [](SpinLockMutex &m) { m.unlock(); });
}

// Naive `while(try_lock()) {}` implementation of lock.
Expand Down
3 changes: 1 addition & 2 deletions api/test/nostd/shared_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ TEST(SharedPtrTest, PointerOperators)
shared_ptr<int> ptr1{value};

EXPECT_EQ(&*ptr1, value);
EXPECT_EQ(
shared_ptr<B> { new B }->f(), 123);
EXPECT_EQ(shared_ptr<B> { new B } -> f(), 123);
}

TEST(SharedPtrTest, Swap)
Expand Down
3 changes: 1 addition & 2 deletions api/test/nostd/unique_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ TEST(UniquePtrTest, PointerOperators)
unique_ptr<int> ptr1{value};

EXPECT_EQ(&*ptr1, value);
EXPECT_EQ(
unique_ptr<B> { new B }->f(), 123);
EXPECT_EQ(unique_ptr<B> { new B } -> f(), 123);
}

TEST(UniquePtrTest, Reset)
Expand Down
3 changes: 2 additions & 1 deletion api/test/singleton/component_g.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ extern "C"
__declspec(dllexport)
#endif

void do_something_in_g()
void
do_something_in_g()
{
auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::library"));

Expand Down
9 changes: 5 additions & 4 deletions api/test/singleton/component_h.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ extern "C"
__declspec(dllexport)

#else
// component_h is a shared library (*.so)
// component_h is compiled with visibility("hidden"),
__attribute__((visibility("default")))
// component_h is a shared library (*.so)
// component_h is compiled with visibility("hidden"),
__attribute__((visibility("default")))
#endif

void do_something_in_h()
void
do_something_in_h()
{
auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::library"));

Expand Down
Loading
Loading