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

Switch statements default case not registered as guaranteed return #236

Closed
Headline opened this issue Sep 24, 2018 · 5 comments
Labels
bug

Comments

@Headline
Copy link
Member

@Headline Headline commented Sep 24, 2018

Seems like the default case on switches aren't seen by the compiler as a definite return, and gives us a warning. See testcase below

int main() {
	funct(2);
}
int funct(int input) {
	switch (input) {
		case 0:
			return 1;
		case 1:
			return 2;
		default:
			return 3;
	}
} // warning 209: function "funct" should return a value
@Headline Headline added the bug label Sep 24, 2018
@KyleSanderson

This comment has been minimized.

Copy link
Member

@KyleSanderson KyleSanderson commented Sep 25, 2018

Doesn't gcc render the same? I swear I've seen this same pattern with a multitude of compilers and it's (slightly) expected. I'd definitely label this as an enhancement though as we've already taken a strong stance on how switch works (prior to Go; I guess).

@Headline

This comment has been minimized.

Copy link
Member Author

@Headline Headline commented Sep 25, 2018

oh; it very well might. I'll check, if so I'll close this

@Headline

This comment has been minimized.

Copy link
Member Author

@Headline Headline commented Sep 28, 2018

@KyleSanderson Looks like gcc & clang doesn't warn, I'll keep this up

@Headline Headline added enhancement and removed bug labels Sep 28, 2018
@assyrianic

This comment has been minimized.

Copy link

@assyrianic assyrianic commented Sep 29, 2018

@Headline C and C++ do not warn about this, both compile as assuming the default will be the return value. It's pointless to have an ending return expression if the default case label also contains a return expression.

@dvander

This comment has been minimized.

Copy link
Member

@dvander dvander commented Sep 29, 2018

Just to be clear, this is a valid bug.

@Headline Headline added bug and removed enhancement labels Sep 29, 2018
dvander added a commit that referenced this issue Sep 29, 2018
dvander added a commit that referenced this issue Sep 29, 2018
dvander added a commit that referenced this issue Sep 29, 2018
dvander added a commit that referenced this issue Sep 29, 2018
@dvander dvander closed this in 77b4b87 Sep 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.