lundi 1 juin 2015

Prevent casting uint64_t to uint16_t

Why does the following code compile in clang++?

Are there any c++ flags to prevent this from happening - I would like the compiler to throw an error because I am passing a std::uint64_t as an argument to a function that accepts std::uint16_t.

#include <cstdint>
using namespace std;

void foo(uint16_t x) {
}

int main() {
    uint64_t x = 10000;
    foo(x);
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire