Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Cannot compile with GCC10 #172

Open
olewales opened this issue Sep 26, 2020 · 0 comments
Open

Cannot compile with GCC10 #172

olewales opened this issue Sep 26, 2020 · 0 comments

Comments

@olewales
Copy link

Trying to compile firmware with gcc 10 yields following error:

(...)
/home/olewales/portapack-hackrf/firmware/baseband/spectrum_collector.cpp: In instantiation of 'typename T::value_type spectrum_window_hamming_3(const T&, size_t) [with T = std::array<std::complex<float>, 256>; typename T::value_type = std::complex<float>; size_t = unsigned int]':
/home/olewales/portapack-hackrf/firmware/baseband/spectrum_collector.cpp:142:79:   required from here
/home/olewales/portapack-hackrf/firmware/baseband/spectrum_collector.cpp:114:28: error: non-constant condition for static assertion
  114 |  static_assert(power_of_two(s.size()), "Array size must be power of 2");
      |                ~~~~~~~~~~~~^~~~~~~~~~
/home/olewales/portapack-hackrf/firmware/baseband/spectrum_collector.cpp:114:28: error: 's' is not a constant expression
/home/olewales/portapack-hackrf/firmware/baseband/spectrum_collector.cpp:115:19: error: 's' is not a constant expression
  115 |  constexpr size_t mask = s.size() - 1;
      |                   ^~~~
make[2]: *** [firmware/baseband/CMakeFiles/baseband_shared.dir/build.make:1135: firmware/baseband/CMakeFiles/baseband_shared.dir/spectrum_collector.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:991: firmware/baseband/CMakeFiles/baseband_shared.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

Code may be made to compile by removing constexpr and assertion but there should be a better way to fix this

diff --git a/firmware/baseband/spectrum_collector.cpp b/firmware/baseband/spectrum_collector.cpp
index ebe55a2..dd52da2 100644
--- a/firmware/baseband/spectrum_collector.cpp
+++ b/firmware/baseband/spectrum_collector.cpp
@@ -111,8 +111,8 @@ static typename T::value_type spectrum_window_none(const T& s, const size_t i) {
 
 template<typename T>
 static typename T::value_type spectrum_window_hamming_3(const T& s, const size_t i) {
-       static_assert(power_of_two(s.size()), "Array size must be power of 2");
-       constexpr size_t mask = s.size() - 1;
+       //static_assert(power_of_two(s.size()), "Array size must be power of 2");
+       const size_t mask = s.size() - 1;
        // Three point Hamming window.
        return s[i] * 0.54f + (s[(i-1) & mask] + s[(i+1) & mask]) * -0.23f;
 };

I believe this is related to a bug fixed in GCC10: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66477

GCC version:

$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/10.2.0/lto-wrapper
Target: arm-none-eabi
Configured with: /build/arm-none-eabi-gcc/src/gcc-10.2.0/configure --target=arm-none-eabi --prefix=/usr --with-sysroot=/usr/arm-none-eabi --with-native-system-header-dir=/include --libexecdir=/usr/lib --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-system-zlib --with-newlib --with-headers=/usr/arm-none-eabi/include --with-python-dir=share/gcc-arm-none-eabi --with-gmp --with-mpfr --with-mpc --with-isl --with-libelf --enable-gnu-indirect-function --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='Arch Repository' --with-bugurl=https://bugs.archlinux.org/ --with-multilib-list=rmprofile
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Arch Repository) 
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant