__cxa_rethrow instead of __cxa_end_catch when omitting curly braces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

while analyzing a bug in my software I encountered an interesting behavior of GCC (and also e.g. Clang) which I do not understand. I think it is some corner-case of the C++ standard, but maybe you can help me and explain the behavior I see.

Let's consider the simple test program below.

#include <iostream>

namespace test
{

class Test
{
public:
    Test();
    ~Test();
};

Test::Test()
{
}

Test::~Test()
{
try {
    throw std::exception();
} catch (const std::exception& e) {
    std::cout << "test" << std::endl;
}
}

}

Compiling this e.g. in Godbolt using ARM64 gcc results in the catch block being generated with a __cxa_begin_catch and __cxa_end_catch. However, when I now omit the curly braces in the Test destructor, i.e. in case I write ...

Test::~Test()
try {
    throw std::exception();
} catch (const std::exception& e) {
    std::cout << "test" << std::endl;
}

... it still compiles without any warning, but now the generated assembly contains an unconditional __cxa_rethrow. So how does omitting the curly braces change the interpretation of this code?

Cheers,
Christoph




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux