简体   繁体   中英

Why GCC can compile std::exception(“some error msg”) without error?

I found the following code that is throwing an exception with a message for the parameter, but GCC can successfully compile it without any error.

When I use clang to compile, the result is failure. I want to debug the GCC compile process to find the difference with the GCC option -Q , but it seems not to work. I hope someone can give me some advice, or tell me why GCC can compile it successfully.

T* lpItem = new T;
if (NULL == lpItem)
{
    throw std::exception("New CachePool Item Fail");
}

GCC is taking advantage of [member.functions] to add something like

std::exception::exception(const char *);

Clang is not

For a non-virtual member function described in the C++ standard library, an implementation may declare a different set of member function signatures, provided that any call to the member function that would select an overload from the set of declarations described in this document behaves as if that overload were selected. [ Note: For instance, an implementation may add parameters with default values, or replace a member function with default arguments with two or more member functions with equivalent behavior, or add additional signatures for a member function name. end note ]

Emphasis added

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM