Questions tagged [nothrow]

25 questions
2
votes
2 answers

Preferred Way of Building Strings in D

What is the preferred way of constructing strings with regards to the function attributes @safe, pure and nothrow and compile-time and run-time performance of the parenting function? Should we either use, for instance format("Variable x=%s should…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
1
vote
1 answer

Is constructor called if nothrow new return nullptr?

If I use new and get std::bad_alloc compiler do not call constructor because of exception. But how does it works with the nothrow new cause we get pointer in every case? Is there special paragraph in standard for this case?
dasfex
  • 1,148
  • 2
  • 12
  • 30
1
vote
0 answers

Nothrow not working, even with correct header? (GCC C++)

For the life of me I can't fiqure out why nothrow isn't working. I've tried different headers. Also interchanged the the new and memory headers and still the same output: 0x61ff50 6422400 How many numbers would you like to type:…
Mr SnowGlobe
  • 57
  • 1
  • 8
1
vote
1 answer

Linux g++ new (std::nothrow) does work

I am using c++ constant value std::nothrow in new operator to avoid exception on failure, and return a null instead. But as I tried, this seems not work on my environment is g++ 4.4.4 on Linux x86_64. Following is the testing program and execution…
Hui
  • 127
  • 1
  • 9
1
vote
1 answer

operator++() nothrow does not compile

Why can't I make operator++() nothrow? This could be one of the few advantages of using the postfix ++ operator (over the prefix ++ operator). For example, this code does not compile class Number { public: Number& operator++ () // ++ prefix …
Damian
  • 4,395
  • 4
  • 39
  • 67
1
vote
3 answers

C++ : What shall it be returned when out of memory?

When I code as below, it'll return 'null' and no exception occured. Char* pStr = new(std::nothrow)Char(10); What about not using 'nothrow' argument on new operator? Does it also returns 'null'? If so, why is it recommended to use 'nothrow'…
0
votes
2 answers

C++: Which floating-point operations, if any, are guaranteed by the standard to be non-throwing?

In C++20 (or later), are there any operations involving floating point numbers that are guaranteed by the standard to never throw? What about assignment and copy construction? comparison? arithmetic? Note, I am concerned here only with ordinary…
Kristian Spangsege
  • 2,903
  • 1
  • 20
  • 43
0
votes
1 answer

Undefined reference to std::nothrow in libsupc++.a of newlib

Now I am trying to cross compile Nuttx with libc++ using arm-none-eabi toolchain. Most of things is fine, however some C++ applications have an undefined reference to std::nothrow. I found out that std::nothrow seems to be defined in libsupc++.a in…
0
votes
2 answers

Use of undeclared identifier 'nothrow'; did you mean 'throw'? memory

I am working on a cpp code to port one application from Windows to Mac. While building the application in Xcode it throws the error saying: "Use of undeclared identifier 'nothrow'; did you mean 'throw'? memory" These errors are thrown in cpp…
-1
votes
1 answer

(std::no throw) crashes when allocation fails

I have a custom memory allocator written something like void* Object::operator new(std::size_t size, const std::nothrow_t& nothrow_value) { void *p = Allocator->malloc(size); return p; } Since the standard says I shouldn't throw an exception, I…
302Found
  • 490
  • 7
  • 19
1
2