Skip to content

Increment incorrectly allowed for bool in unevaluated contexts #47517

@CaseyCarter

Description

@CaseyCarter
Bugzilla Link 48173
Version trunk
OS All
CC @Quuxplusone,@zygoloid

Extended Description

Compiling this well-formed program:

template <class T>
concept can_increment = requires(T t) {
    ++t;
};

template <class T>
void f() {
    static_assert(requires(T t) { ++t; }); // Incorrectly allowed
}

int main() {
    f<bool>();

    static_assert(!can_increment<bool>); // Incorrectly fails

    bool b = false;
    ++b; // Correctly rejected
}

with "clang++ -std=c++2a" (https://godbolt.org/z/39xM1E) diagnoses:

<source>:14:5: error: static_assert failed due to requirement '!can_increment<bool>'
    static_assert(!can_increment<bool>); // Incorrectly fails
    ^             ~~~~~~~~~~~~~~~~~~~~
<source>:17:5: error: ISO C++17 does not allow incrementing expression of type bool [-Wincrement-bool]
    ++b;
    ^ ~

The compiler knows that the language forbids increment of bools outside a requires-expression, but apparently not within a requires-expression.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillac++17c++20clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions