Skip to content

Commit 5ec0631

Browse files
committed
build(c): work around clang making __COUNTER__ a warning
Closes apache#4042.
1 parent bb3f4bf commit 5ec0631

File tree

3 files changed

+63
-15
lines changed

3 files changed

+63
-15
lines changed

c/driver/framework/statement.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ class Statement : public BaseStatement<Derived> {
207207
// No-op
208208
return status::Ok();
209209
} else if constexpr (std::is_same_v<T, QueryState>) {
210-
UNWRAP_STATUS(impl().PrepareImpl(state));
210+
// unwrap macro appears to fail due to -Wc2y-extensions
211+
// which for some reason doesn't get suppressed here
212+
auto status = impl().PrepareImpl(state);
213+
if (!status.ok()) {
214+
return status;
215+
}
211216
state_ = PreparedState{std::move(state.query)};
212217
return status::Ok();
213218
} else {

c/driver/framework/status.h

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434

3535
/// \file status.h
3636

37+
#if defined(__clang__)
38+
// See https://github.com/google/benchmark/pull/2108
39+
#define IGNORE_COUNTER_WARNING \
40+
_Pragma("GCC diagnostic push"); \
41+
_Pragma("GCC diagnostic ignored \"-Wunknown-warning-option\""); \
42+
_Pragma("GCC diagnostic ignored \"-Wc2y-extensions\"");
43+
#define RESTORE_COUNTER_WARNING _Pragma("GCC diagnostic pop")
44+
#else
45+
#define IGNORE_COUNTER_WARNING
46+
#define RESTORE_COUNTER_WARNING
47+
#endif
48+
3749
namespace adbc::driver {
3850

3951
/// \brief A wrapper around AdbcStatusCode + AdbcError.
@@ -274,17 +286,26 @@ class Result {
274286
#define UNWRAP_RESULT_NAME(x, y) DRIVER_CONCAT(x, y)
275287

276288
/// \brief A helper to unwrap a Result in functions returning AdbcStatusCode.
277-
#define RAISE_RESULT(ERROR, LHS, RHS) \
278-
RAISE_RESULT_IMPL(UNWRAP_RESULT_NAME(driver_raise_result, __COUNTER__), ERROR, LHS, RHS)
289+
#define RAISE_RESULT(ERROR, LHS, RHS) \
290+
IGNORE_COUNTER_WARNING \
291+
RAISE_RESULT_IMPL(UNWRAP_RESULT_NAME(driver_raise_result, __COUNTER__), ERROR, LHS, \
292+
RHS) \
293+
RESTORE_COUNTER_WARNING
279294
/// \brief A helper to unwrap a Status in functions returning AdbcStatusCode.
280-
#define RAISE_STATUS(ERROR, RHS) \
281-
RAISE_STATUS_IMPL(UNWRAP_RESULT_NAME(driver_raise_status, __COUNTER__), ERROR, RHS)
295+
#define RAISE_STATUS(ERROR, RHS) \
296+
IGNORE_COUNTER_WARNING \
297+
RAISE_STATUS_IMPL(UNWRAP_RESULT_NAME(driver_raise_status, __COUNTER__), ERROR, RHS) \
298+
RESTORE_COUNTER_WARNING
282299
/// \brief A helper to unwrap a Result in functions returning Result/Status.
283-
#define UNWRAP_RESULT(lhs, rhs) \
284-
UNWRAP_RESULT_IMPL(UNWRAP_RESULT_NAME(driver_unwrap_result, __COUNTER__), lhs, rhs)
300+
#define UNWRAP_RESULT(lhs, rhs) \
301+
IGNORE_COUNTER_WARNING \
302+
UNWRAP_RESULT_IMPL(UNWRAP_RESULT_NAME(driver_unwrap_result, __COUNTER__), lhs, rhs) \
303+
RESTORE_COUNTER_WARNING
285304
/// \brief A helper to unwrap a Status in functions returning Result/Status.
286-
#define UNWRAP_STATUS(rhs) \
287-
UNWRAP_STATUS_IMPL(UNWRAP_RESULT_NAME(driver_unwrap_status, __COUNTER__), rhs)
305+
#define UNWRAP_STATUS(rhs) \
306+
IGNORE_COUNTER_WARNING \
307+
UNWRAP_STATUS_IMPL(UNWRAP_RESULT_NAME(driver_unwrap_status, __COUNTER__), rhs) \
308+
RESTORE_COUNTER_WARNING
288309

289310
} // namespace adbc::driver
290311

@@ -344,8 +365,10 @@ STATUS_CTOR(Unknown, UNKNOWN)
344365
std::strerror(NAME)); \
345366
}
346367

347-
#define UNWRAP_ERRNO(CODE, RHS) \
348-
UNWRAP_ERRNO_IMPL(UNWRAP_RESULT_NAME(driver_errno, __COUNTER__), CODE, RHS)
368+
#define UNWRAP_ERRNO(CODE, RHS) \
369+
IGNORE_COUNTER_WARNING \
370+
UNWRAP_ERRNO_IMPL(UNWRAP_RESULT_NAME(driver_errno, __COUNTER__), CODE, RHS) \
371+
RESTORE_COUNTER_WARNING
349372

350373
#define UNWRAP_NANOARROW_IMPL(NAME, ERROR, CODE, RHS) \
351374
auto&& NAME = (RHS); \
@@ -355,5 +378,7 @@ STATUS_CTOR(Unknown, UNKNOWN)
355378
}
356379

357380
#define UNWRAP_NANOARROW(ERROR, CODE, RHS) \
381+
IGNORE_COUNTER_WARNING \
358382
UNWRAP_NANOARROW_IMPL(UNWRAP_RESULT_NAME(driver_errno_na, __COUNTER__), ERROR, CODE, \
359-
RHS)
383+
RHS) \
384+
RESTORE_COUNTER_WARNING

c/vendor/nanoarrow/nanoarrow.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@
5454
// specific language governing permissions and limitations
5555
// under the License.
5656

57+
#if defined(__clang__)
58+
// See https://github.com/google/benchmark/pull/2108
59+
#define NANOARROW_IGNORE_COUNTER_WARNING \
60+
_Pragma("GCC diagnostic push") \
61+
_Pragma("GCC diagnostic ignored \"-Wunknown-warning-option\"") \
62+
_Pragma("GCC diagnostic ignored \"-Wc2y-extensions\"")
63+
#define NANOARROW_RESTORE_COUNTER_WARNING _Pragma("GCC diagnostic pop")
64+
#else
65+
#define NANOARROW_IGNORE_COUNTER_WARNING
66+
#define NANOARROW_RESTORE_COUNTER_WARNING
67+
#endif
68+
5769
#ifndef NANOARROW_NANOARROW_TYPES_H_INCLUDED
5870
#define NANOARROW_NANOARROW_TYPES_H_INCLUDED
5971

@@ -305,7 +317,9 @@ static inline void ArrowErrorSetString(struct ArrowError* error, const char* src
305317
/// \brief Check the result of an expression and return it if not NANOARROW_OK
306318
/// \ingroup nanoarrow-errors
307319
#define NANOARROW_RETURN_NOT_OK(EXPR) \
308-
_NANOARROW_RETURN_NOT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR)
320+
NANOARROW_IGNORE_COUNTER_WARNING \
321+
_NANOARROW_RETURN_NOT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR) \
322+
NANOARROW_RESTORE_COUNTER_WARNING
309323

310324
/// \brief Check the result of an expression and return it if not NANOARROW_OK,
311325
/// adding an auto-generated message to an ArrowError.
@@ -315,8 +329,10 @@ static inline void ArrowErrorSetString(struct ArrowError* error, const char* src
315329
/// as input always set its message when returning an error code (e.g., when calling
316330
/// a nanoarrow function that does *not* accept ArrowError).
317331
#define NANOARROW_RETURN_NOT_OK_WITH_ERROR(EXPR, ERROR_EXPR) \
332+
NANOARROW_IGNORE_COUNTER_WARNING \
318333
_NANOARROW_RETURN_NOT_OK_WITH_ERROR_IMPL( \
319-
_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, ERROR_EXPR, #EXPR)
334+
_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, ERROR_EXPR, #EXPR) \
335+
NANOARROW_RESTORE_COUNTER_WARNING
320336

321337
#if defined(NANOARROW_DEBUG) && !defined(NANOARROW_PRINT_AND_DIE)
322338
#define NANOARROW_PRINT_AND_DIE(VALUE, EXPR_STR) \
@@ -343,7 +359,9 @@ static inline void ArrowErrorSetString(struct ArrowError* error, const char* src
343359
/// be defining the NANOARROW_PRINT_AND_DIE macro before including nanoarrow.h
344360
/// This macro is provided as a convenience for users and is not used internally.
345361
#define NANOARROW_ASSERT_OK(EXPR) \
346-
_NANOARROW_ASSERT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, #EXPR)
362+
NANOARROW_IGNORE_COUNTER_WARNING \
363+
_NANOARROW_ASSERT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, #EXPR) \
364+
NANOARROW_RESTORE_COUNTER_WARNING
347365

348366
#define _NANOARROW_DCHECK_IMPL(EXPR, EXPR_STR) \
349367
do { \

0 commit comments

Comments
 (0)