#include <iostream>
void test(const char* p)
{
char c = *p; // 1
std::cout << p << std::endl;
}
template <typename T>
void test_tmp(T&& x)
{
auto aa = (T&&)x; //追加 1 <= これでアクセス違反
auto bb = static_cast<T&&>(x); //追加 2 <= OK
test(x); // 2
test((T&&)x); // 3
}
int main() {
typedef const char* const_char_p;
test("NHK"); // 4
test((const_char_p&&)"JCB"); // 5
test_tmp("JiNS"); // 6
// VC だと 6 => 3 => 1 の呼び出しでアクセス違反終了
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdm9pZCB0ZXN0KGNvbnN0IGNoYXIqIHApCnsKCWNoYXIgYyA9ICpwOwkJLy8gMQoJc3RkOjpjb3V0IDw8IHAgPDwgc3RkOjplbmRsOwp9Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4Kdm9pZCB0ZXN0X3RtcChUJiYgeCkKewoJYXV0byBhYSA9IChUJiYpeDsJCQkJCS8v6L+95YqgIDEgPD0g44GT44KM44Gn44Ki44Kv44K744K56YGV5Y+NCglhdXRvIGJiID0gc3RhdGljX2Nhc3Q8VCYmPih4KTsJCS8v6L+95YqgIDIgPD0gT0sKCXRlc3QoeCk7CQkJLy8gMgoJdGVzdCgoVCYmKXgpOwkJLy8gMwp9CgoKaW50IG1haW4oKSB7Cgl0eXBlZGVmIGNvbnN0IGNoYXIqICBjb25zdF9jaGFyX3A7Cgl0ZXN0KCJOSEsiKTsJCQkJCS8vIDQKCXRlc3QoKGNvbnN0X2NoYXJfcCYmKSJKQ0IiKTsJLy8gNQoJdGVzdF90bXAoIkppTlMiKTsJCQkJLy8gNgoJLy8gVkMg44Gg44GoIDYgPT4gMyA9PiAxIOOBruWRvOOBs+WHuuOBl+OBp+OCouOCr+OCu+OCuemBleWPjee1guS6hgoJcmV0dXJuIDA7Cn0=