我不明白为什么我没有得到一个警告(使用g ++或铛++)在下面newtstr()
返回NULL作为对象没有得到任何警告。NULL返回时为对象
$ g++ -Wall -Wextra -pedantic testptr.cpp
$
我做的,但是,得到一个运行时错误:
$ ./a.out
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
Aborted
$
。
$ g++ --version
g++ (GCC) 4.8.0
你已经标记了这个铿锵声++。这是否也适用于铿锵声? –
你为什么期待警告?这是一个有效的构造。 – ZDF
@ZDF OP或者不知道隐式的'const char *'强制转换,或者他期望他的编译器看到“嘿,这是一个静态表达式,它给了我一个零指针,'string'ctor试图做的东西,它应该能够警告我这件事!“ –