Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not throw std::bad_cast from antlrcpp::Any::is #2406

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions runtime/Cpp/runtime/src/support/Any.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ struct ANTLR4CPP_PUBLIC Any

template<class U>
bool is() const {
auto derived = getDerived<U>();
auto derived = getDerived<U>(false);

return derived != nullptr;
}

template<class U>
StorageType<U>& as() {
auto derived = getDerived<U>();
auto derived = getDerived<U>(true);

return derived->value;
}

template<class U>
const StorageType<U>& as() const {
auto derived = getDerived<U>();
auto derived = getDerived<U>(true);

return derived->value;
}
Expand Down Expand Up @@ -143,12 +143,12 @@ struct ANTLR4CPP_PUBLIC Any
}

template<class U>
Derived<StorageType<U>>* getDerived() const {
Derived<StorageType<U>>* getDerived(bool checkCast) const {
typedef StorageType<U> T;

auto derived = dynamic_cast<Derived<T>*>(_ptr);

if (!derived)
if (checkCast && !derived)
throw std::bad_cast();

return derived;
Expand Down