Skip to content

C-style casts break compilation with -Wold-style-cast -Werror (GCC 14/15, C++23) #444

@PavelGuzenfeld

Description

@PavelGuzenfeld

Problem

Projects that compile with strict warning flags (-Wold-style-cast -Wuseless-cast -Werror) cannot include concurrentqueue.h, blockingconcurrentqueue.h, or lightweightsemaphore.h without errors on GCC 14/15 with C++17/20/23.

This is a common configuration for modern C++ codebases following strict coding standards.

Reproduction

#include "concurrentqueue.h"
#include "blockingconcurrentqueue.h"

int main() {
    moodycamel::BlockingConcurrentQueue<int> q;
    q.enqueue(42);
    int item;
    q.wait_dequeue_timed(item, std::chrono::milliseconds(1));
    return 0;
}
g++ -std=c++23 -Wall -Wextra -Wpedantic -Werror -Wold-style-cast -Wuseless-cast \
    test.cpp -o test -lpthread

Result: 20+ errors from C-style casts across the three headers.

Affected locations

  • lightweightsemaphore.h: C-style casts (time_t), (long), (std::uint64_t), (int) in timed_wait, waitWithPartialSpinning, waitManyWithPartialSpinning, signal
  • blockingconcurrentqueue.h: C-style casts (int), (size_t), (ssize_t), (LightweightSemaphore::ssize_t), (BlockingConcurrentQueue*) across constructors, enqueue_bulk, try_enqueue_bulk, try_dequeue_bulk, wait_dequeue_bulk, wait_dequeue_bulk_timed, size_approx
  • concurrentqueue.h: -Wuseless-cast on static_cast<size_t> in hash_thread_id (cast is needed for 32-bit cross-platform correctness but redundant on 64-bit)

Environment

  • GCC 14.2.0, GCC 15.2.0
  • C++17, C++20, C++23
  • Linux x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions