Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22015

Can nullptr be converted to uintptr_t? Different compilers disagree

$
0
0

Consider this program:

#include <cstdint>
using my_time_t = uintptr_t;

int main() {
    const my_time_t t = my_time_t(nullptr);
}

It failed to compile with msvc v19.24:

<source>(5): error C2440: '<function-style-cast>': cannot convert from 'nullptr' to 'my_time_t'<source>(5): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
<source>(5): error C2789: 't': an object of const-qualified type must be initialized
<source>(5): note: see declaration of 't'

Compiler returned: 2

but clang (9.0.1) and gcc (9.2.1) "eat" this code without any errors.

I like the MSVC behaviour, but is it confirmed by standard? In other words is it bug in clang/gcc or it is possible to interpret standard that this is right behaviour from gcc/clang?


Viewing all articles
Browse latest Browse all 22015

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>