Last active
September 8, 2023 22:15
-
-
Save mmomtchev/64156d9391984f7695d8556974b1611b to your computer and use it in GitHub Desktop.
msvc-exception-lambda-bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Magick++.h> | |
#include <exception> | |
#include <functional> | |
#include <string> | |
typedef std::function<const char *()> MakeErr; | |
class LambdaException : public std::exception { | |
MakeErr get_err; | |
public: | |
LambdaException(MakeErr err) : get_err(err) {} | |
virtual ~LambdaException(){}; | |
const char *Error() const { return get_err(); } | |
}; | |
int main() { | |
try { | |
try { | |
throw Magick::Exception("error", NULL); | |
} catch (const Magick::Exception &e) { | |
throw LambdaException([e2 = Magick::Exception(e)]() { return e2.what(); }); | |
} | |
} catch (const LambdaException &e) { | |
printf("%s\n", e.Error()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <exception> | |
#include <functional> | |
#include <string> | |
typedef std::function<const char *()> MakeErr; | |
class LambdaException : public std::exception { | |
MakeErr get_err; | |
public: | |
LambdaException(MakeErr err) : get_err(err) {} | |
virtual ~LambdaException(){}; | |
const char *Error() const { return get_err(); } | |
}; | |
int main() { | |
try { | |
try { | |
throw std::exception(); | |
} catch (const std::exception &e) { | |
throw LambdaException([e]() { return e.what(); }); | |
} | |
} catch (const LambdaException &e) { | |
printf("%s\n", e.Error()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second case, compile
mismatch between constructors and destructors:
(every line show the
this
pointer,what()
andnested
which isNULL
)