This code is as follows:
void f() { int i; i = 0; }
Is it possible that the system may throw an exception due to a simple assignment?
[Edit: For those who say, โNo exception can happen,โ can you point Me toward the part of the C ++ standard that talks about this? It's hard for me to find him.]
Although it will probably be difficult for you to find confidence in it in the standard, a simple rule of thumb is that anything that is legitimate in C may not give up. [Edit: the closest that I know of, a direct statement on this subject is in ยง15 / 2, which states that:
, throw, "throw exception"; [...]
, , throw, .]
: UB. - ++, , , operator = new.
operator =
new
. , , . , , . , , - .
, , :
int operator"" _t(const char *) { throw 0; } // C++11 user defined literal struct foo { foo(int) { throw 0; } operator int() { throw 0; } foo& operator=(int) { throw 0; } }; int main() { int i; i = 0; // can't throw i = 0_t; // User defined literal throws foo f = 0; // Constructor throws i = f; // conversion operator throws f = 0; // assignment throws f = f; // both conversion and assignment would like to throw }
( ++ 11)
, 0 ( int) int, ยง 5.17 , , . int, ยง5.17 , " cv-unqualified . " :
0
int
, int, ( C : int , , )
, undefined, int, undefined ( )
, . .
: , , , . , operator=. , , .
operator=
: operator=() ; , , operator T() . , - , , , .
operator=()
operator T()
int, - .
- , , , (, ).