-
Notifications
You must be signed in to change notification settings - Fork 273
Make a few changes suggested by @smowton #1471
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ Author: Nathan Phillips <[email protected]> | |
/// \tparam T The exprt-derived class to check for | ||
/// \param base Reference to a generic \ref exprt | ||
/// \return true if \a base is of type \a T | ||
template<typename T> bool can_cast_expr(const exprt &base); | ||
template<typename T> inline bool can_cast_expr(const exprt &base); | ||
|
||
/// Called after casting. Provides a point to assert on the structure of the | ||
/// expr. By default, this is a no-op, but you can provide an overload to | ||
|
@@ -45,7 +45,8 @@ struct expr_try_dynamic_cast_return_typet final | |
{ | ||
static_assert( | ||
!std::is_reference<Ret>::value, | ||
"Ret must be non-qualified"); | ||
"Ret must not be a reference, i.e. expr_try_dynamic_cast<const thingt> " | ||
"rather than expr_try_dynamic_cast<const thing &>"); | ||
|
||
typedef | ||
typename std::conditional< | ||
|
@@ -78,7 +79,7 @@ auto expr_try_dynamic_cast(TExpr &base) | |
static_assert( | ||
std::is_base_of<exprt, T>::value, | ||
"The template argument T must be derived from exprt."); | ||
if(!can_cast_expr<T>(base)) | ||
if(!can_cast_expr<typename std::remove_const<T>::type>(base)) | ||
return nullptr; | ||
const auto ret=static_cast<returnt>(&base); | ||
validate_expr(*ret); | ||
|
@@ -93,7 +94,8 @@ struct expr_dynamic_cast_return_typet final | |
{ | ||
static_assert( | ||
!std::is_reference<Ret>::value, | ||
"Ret must be non-qualified"); | ||
"Ret must not be a reference, i.e. expr_dynamic_cast<const thingt> rather " | ||
"than expr_dynamic_cast<const thing &>"); | ||
|
||
typedef | ||
typename std::conditional< | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means missing definitions are flagged at compile time rather than link time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't look like common practice, I'd put that comment in the code.
Also it looks like
can_cast_expr
should have been expressed as a meta function. Inline is merely a suggestion for the compiler to inline. It might work differently on debug and release modes and different compilers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so in this case -- if it's declared inline, then the compiler knows it definitely wants a definition in this unit, rather than generating an extern symbol and waiting for the linker to solve the problem. It's still free to choose whether to actually inline or compile out-of-line and flag it for merging with other units' definitions.