fix: explicitly mark unreachable code to prevent GCC warnings#642
Closed
mhx wants to merge 1 commit into
Closed
Conversation
Contributor
|
@createdbysk has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
vitaut
requested changes
Mar 18, 2025
vitaut
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR! Introducing assume_unreachable seems like an overkill. Let's use std::terminate or throw std::logic_error instead.
Currently, GCC warns about code that switches on an enum, but despite
handling all enumerations, will not return a value in the default case.
thrift/compiler/sema/check_map_keys.cc: In function 'bool apache::thrift::compiler::{anonymous}::lt_value(const apache::thrift::compiler::t_const_value*, const apache::thrift::compiler::t_const_value*)':
thrift/compiler/sema/check_map_keys.cc:167:1: warning: control reaches end of non-void function [-Wreturn-type]
167 | }
| ^
This change adds `abort()` after each of these switch statement, the
same approach as used e.g. in `t_const_value::kind_to_string`.
f1b961a to
68b62cc
Compare
Contributor
Author
That's fair. I've actually found this code, which uses |
Contributor
|
@createdbysk has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
|
@createdbysk merged this pull request in e462db1. |
facebook-github-bot
pushed a commit
to facebook/hhvm
that referenced
this pull request
Mar 20, 2025
Summary:
Currently, GCC warns about code that switches on an enum, but despite handling all enumerations, will not return a value in the default case.
thrift/compiler/sema/check_map_keys.cc: In function 'bool apache::thrift::compiler::{anonymous}::lt_value(const apache::thrift::compiler::t_const_value*, const apache::thrift::compiler::t_const_value*)':
thrift/compiler/sema/check_map_keys.cc:167:1: warning: control reaches end of non-void function [-Wreturn-type]
167 | }
| ^
This change adds `abort()` after each of these switch statement, the same approach as used e.g. in `t_const_value::kind_to_string`.
X-link: facebook/fbthrift#642
Reviewed By: vitaut
Differential Revision: D71357532
Pulled By: createdbysk
fbshipit-source-id: ec1a29e74429f7db83f9fb7b811bee06e238679d
Contributor
|
Merged, thanks! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, GCC warns about code that switches on an enum, but despite handling all enumerations, will not return a value in the default case.
This change adds
abort()after each of these switch statement, the same approach as used e.g. int_const_value::kind_to_string.