mercredi 24 mai 2023

Compilation failed for type int(&)const

int()const does not make sense for free function but is allowed in c++ type system.

Why do int(&)()const & int(&&)()const cause following compilation error on Clang provided int()const is allowed:

<source>:19:79: error: reference to function type cannot have 'const' qualifier
    static_assert(std::is_same_v<std::add_rvalue_reference_t<int()const>, int(&)()const>);
                                                                              ^
1 error generated.

int()const compiles fine

int main(void) {
    static_assert(std::is_same_v<std::add_rvalue_reference_t<int()const>, int()const>);
    return EXIT_SUCCESS;
}

Aucun commentaire:

Enregistrer un commentaire