The following program throws nullptr
and then catches the exception as int*
:
#include <iostream>
int main() {
try {
throw nullptr;
}
catch(int*) {
std::cout << "caught int*";
}
catch(...) {
std::cout << "caught other";
}
}
In Clang and GCC the program successfully prints caught int*
, demo: https://gcc.godbolt.org/z/789639qbb
However in Visual Studio 16.11.2 the program prints caught other
. Is it a bug in MSVC?
CodePudding user response:
Looks like a bug in Visual Studio, according to the standard [except.handle]:
A handler is a match for an exception object of type
E
if[...]
- the handler is of type
cv T
orconst T&
whereT
is apointer
orpointer-to->member
type andE
isstd::nullptr_t
.