Open wantija opened 1 year ago
Same problem with GCC on openSUSE Tumbleweed. The problem seems to be that GCC (possibly unlike clang) is more fussy (or less intelligent) about reaching the end of a non-void function without a return
statement, as occurs in cubeb_utils.cpp
:
size_t cubeb_sample_size(cubeb_sample_format format)
{
switch (format) {
case CUBEB_SAMPLE_S16LE:
case CUBEB_SAMPLE_S16BE:
return sizeof(int16_t);
case CUBEB_SAMPLE_FLOAT32LE:
case CUBEB_SAMPLE_FLOAT32BE:
return sizeof(float);
default:
// should never happen as all cases are handled above.
assert(false);
}
}
I believe that cubeb's default build may be set up to treat such return-type warnings as errors. The problem can be worked around by adding __builtin_unreachable();
after the switch
statement; this is a non-standard compiler optimization hint that is recognized by GCC (and also Clang, I believe). An alternative solution would be to update the build files with something like Wno-error=return-type
.
This was fixed a while ago in https://github.com/mozilla/cubeb/pull/571/files#diff-c83414b24af193c5d964ce25a94a079c72000e2b868d56d219a676b2ff28f809. The problem in the original post is different, it's a linker issue in a test.
Let me know if it still happens, we mostly use clang these days so an issue with gcc is plausible.
That fix is functionally equivalent to the workaround I propose, and has the advantage of being portable across compilers. I'm able to compile with it. Thanks!
https://en.cppreference.com/w/cpp/utility/unreachable will be available in C++23, but Firefox (and therefore cubeb) is for now a C++17 project. It's not too hard with a little macro work to do a portable version, but what we have work for our purpose indeed.
title, laltest commit e4da2d4 fails to build on arch linux even in a clean chroot. gist the terminal log: https://gist.github.com/wantija/8a91a1fec19781d18dbf01922bc83c4b