Skip to content

Workaround for GCC -Wduplicated-branches #573

Closed
@VaderDev

Description

Hi,

The following line triggers the following GCC 7.1 -Wduplicated-branches warning:

fmt/fmt/format.h

Line 2326 in 2a619d9

typedef Value Type[N > 0 ? N : 1];

fmt/include/fmt/format.h: In instantiation of 'struct fmt::internal::ArgArray<1, true>':
fmt/include/fmt/format.h:3467:1: required from 'std::__cxx11::string fmt::format(fmt::CStringRef, const Args& ...) [with Args = {unsigned int, char [5]}; std::__cxx11::string = std::__cxx11::basic_string<char>; fmt::CStringRef = fmt::BasicCStringRef<char>]'
cc1plus: warning: this condition has identical branches [-Wduplicated-branches]

I am pretty sure this is a false positive scenario for this warning (partial evaluation of compile time expression for this warning doesn't seams right), workaround could be:

static constexpr size_t shut_up_gcc = N;
typedef Value Type[N > 0 ? shut_up_gcc : 1];
// or just:
typedef Value Type[N > 0 ? N + 0 : 1];

I will file a gcc issue for this behavior (and also for the fact that I am including fmt as system headers so I should not get any warnings). My head hurts and I am sorry that I even raised this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions