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

Added default case in switch to avoid warning #716

Open
wants to merge 2 commits into
base: master
from

Conversation

@amallia
Copy link

@amallia amallia commented Nov 9, 2018

warning: missing return statement at end of non-void function "benchmark::GetTimeUnitString"
warning: missing return statement at end of non-void function "benchmark::GetTimeUnitMultiplier"

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

warning: missing return statement at end of non-void function "benchmark::GetTimeUnitString"
warning: missing return statement at end of non-void function "benchmark::GetTimeUnitMultiplier"
@googlebot
Copy link

@googlebot googlebot commented Nov 9, 2018

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
@googlebot googlebot added the cla: no label Nov 9, 2018
@amallia
Copy link
Author

@amallia amallia commented Nov 9, 2018

I signed it!

@googlebot
Copy link

@googlebot googlebot commented Nov 9, 2018

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Nov 9, 2018
@coveralls
Copy link

@coveralls coveralls commented Nov 9, 2018

Coverage Status

Coverage remained the same at 89.224% when pulling 5cdbab7 on amallia:patch-1 into a9b31c5 on google:master.

@@ -1518,6 +1518,7 @@ inline const char* GetTimeUnitString(TimeUnit unit) {
case kMicrosecond:
return "us";
case kNanosecond:
default:
return "ns";
}
BENCHMARK_UNREACHABLE();

This comment has been minimized.

@LebedevRI

LebedevRI Nov 10, 2018
Collaborator

This is the line that is supposed to fix it.
I think you should instead make sure it expands to some this is unreachable your compiler understands.

This comment has been minimized.

@amallia

amallia Nov 10, 2018
Author

The problem is that now all the compilers understand BENCHMARK_UNREACHABLE();

This comment has been minimized.

@amallia

amallia Nov 10, 2018
Author

#define BENCHMARK_UNREACHABLE() ((void)0)

This comment has been minimized.

@LebedevRI

LebedevRI Nov 10, 2018
Collaborator

Have you tried changing that to

#if defined(__GNUC__) || __has_builtin(__builtin_unreachable) || defined(WHATEVER_NVCC_MACRO)
  #define BENCHMARK_UNREACHABLE() __builtin_unreachable()
#elif defined(_MSC_VER)
  #define BENCHMARK_UNREACHABLE() __assume(false)
#else
  #define BENCHMARK_UNREACHABLE() ((void)0)
#endif

?

This comment has been minimized.

@amallia

amallia Nov 10, 2018
Author

I believe since __has_builtin(__builtin_unreachable) is false, it should not make any difference...

This comment has been minimized.

@amallia

amallia Nov 10, 2018
Author

Yes @brenoguim you are correct

This comment has been minimized.

@EricWF

EricWF Nov 10, 2018
Contributor

Does std::abort work? Or any other noreturn function?

This comment has been minimized.

@EricWF

EricWF Nov 10, 2018
Contributor

Disabling that warning on the whole code can be harmful.

Not on the whole of the code base, just for that function. But I'm strongly opposed to adding a default case.

We've discussed this before, and we've decided on this direction.

This comment has been minimized.

@brenoguim

brenoguim Nov 10, 2018

Yeah, adding the default should not be an option.

I like the std::abort suggestion. Writing the BENCHMARK_UNREACHABLE last fallback as std::abort would keep the good code generation for the targets that support it, and silence the warning for the others.

Update based on suggestion #2 from @brenoguim
@LebedevRI
Copy link
Collaborator

@LebedevRI LebedevRI commented Nov 24, 2018

On which compiler is nvcc based? Does it really not have __builtin_unreachable() or some analog of it?

@dominichamon
Copy link
Member

@dominichamon dominichamon commented Mar 18, 2019

do {std::abort(); } while(0) should be a good replacement for unreachable code in any compiler, i think.

@LebedevRI LebedevRI added the incomplete label May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants