Skip to content

<bit>: bit_ceil(T(-1)) should not be a constant expression #1595

@CaseyCarter

Description

@CaseyCarter

Per [bit.pow.two]/8 std::bit_ceil(meow) is not a core constant expression when the smallest power of two greater than or equal to meow is not representable by the type decltype(meow). This is not the case for all supported types and all supported compilers with our implementation as witnessed by this ill-formed TU:

#include <bit>

using UC = unsigned char;
using US = unsigned short;
using UI = unsigned int;
using UL = unsigned long;
using ULL = unsigned long long;

// All static_asserts are ill-formed since their
// arguments are not constant expressions.

// None of Clang/EDG/MSVC diagnose these:
static_assert(((void)std::bit_ceil(UC(-1)), true));
static_assert(((void)std::bit_ceil(US(-1)), true));

// Clang and EDG, but not MSVC, diagnose these:
static_assert(((void)std::bit_ceil(UI(-1)), true));
static_assert(((void)std::bit_ceil(UL(-1)), true));
static_assert(((void)std::bit_ceil(ULL(-1)), true));

There's almost certainly an MSVC compiler bug here, and probably a library bug as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerCompiler work involvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions