Added default case in switch to avoid warning #716
Conversation
warning: missing return statement at end of non-void function "benchmark::GetTimeUnitString" warning: missing return statement at end of non-void function "benchmark::GetTimeUnitMultiplier"
|
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). Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
I signed it! |
|
CLAs look good, thanks! |
|
|
| @@ -1518,6 +1518,7 @@ inline const char* GetTimeUnitString(TimeUnit unit) { | |||
| case kMicrosecond: | |||
| return "us"; | |||
| case kNanosecond: | |||
| default: | |||
| return "ns"; | |||
| } | |||
| BENCHMARK_UNREACHABLE(); | |||
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 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.
amallia
Nov 10, 2018
Author
The problem is that now all the compilers understand BENCHMARK_UNREACHABLE();
The problem is that now all the compilers understand BENCHMARK_UNREACHABLE();
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
?
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
?
amallia
Nov 10, 2018
Author
I believe since __has_builtin(__builtin_unreachable) is false, it should not make any difference...
I believe since __has_builtin(__builtin_unreachable) is false, it should not make any difference...
brenoguim
Nov 10, 2018
Option #2 introduces warnings in MSVC :( https://ci.appveyor.com/project/google/benchmark/builds/20198554/job/ub5ulj85wb67ym3o
Option #2 introduces warnings in MSVC :( https://ci.appveyor.com/project/google/benchmark/builds/20198554/job/ub5ulj85wb67ym3o
EricWF
Nov 10, 2018
Contributor
Does std::abort work? Or any other noreturn function?
Does std::abort work? Or any other noreturn function?
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.
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.
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.
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
|
|
|
On which compiler is nvcc based? Does it really not have |
|
|
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