view gcc/testsuite/g++.dg/cpp0x/nullptr04.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
line wrap: on
line source

// { dg-do compile { target c++11 } }

// Test cast to int

__extension__ typedef __INTPTR_TYPE__ intptr_t;

const int n4 = static_cast<const int>(nullptr); // { dg-error "16:invalid 'static_cast' " }
const short int n5 = reinterpret_cast<short int>(nullptr); // { dg-error "22:cast from .std::nullptr_t. to .short int. loses precision" }
const intptr_t n6 = reinterpret_cast<intptr_t>(nullptr);
const intptr_t n7 = (intptr_t)nullptr;

decltype(nullptr) mynull = 0;
const int n8 = static_cast<const int>(mynull); // { dg-error "16:invalid 'static_cast' " }
const short int n9 = reinterpret_cast<short int>(mynull); // { dg-error "22:cast from .std::nullptr_t. to .short int. loses precision" }
const intptr_t n10 = reinterpret_cast<intptr_t>(mynull);
const intptr_t n11 = (intptr_t)mynull;