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

Compiler error: constexpr function never produces a constant expression [-Winvalid-constexpr] #344

Closed
toco opened this issue Jun 18, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@toco
Copy link

toco commented Jun 18, 2023

Building 5b66246 fails for me with the following errors:

cd /tmp/qdmr-20230618-35854-12ga0el/lib && /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_POSITIONING_LIB -DQT_SERIALPORT_LIB -DQT_WIDGETS_LIB -Dlibdmrconf_EXPORTS -F/usr/local/opt/qt@5/lib -I/usr/local/opt/qt@5/lib/QtWidgets.framework/Headers -I/usr/local/opt/qt@5/lib/QtGui.framework/Headers -I/usr/local/opt/qt@5/include/QtUiTools -I/usr/local/include/libusb-1.0 -I/tmp/qdmr-20230618-35854-12ga0el/src -I/tmp/qdmr-20230618-35854-12ga0el/lib -isystem /usr/local/opt/qt@5/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt@5/./mkspecs/macx-clang -isystem /usr/local/opt/qt@5/lib/QtNetwork.framework/Headers -isystem /usr/local/opt/qt@5/lib/QtSerialPort.framework/Headers -isystem /usr/local/opt/qt@5/lib/QtPositioning.framework/Headers -Wall -Wsign-compare -O3 -DNDEBUG -O3 -Wextra -std=gnu++14 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -fPIC -fPIC -MD -MT lib/CMakeFiles/libdmrconf.dir/hid_macos.cc.o -MF CMakeFiles/libdmrconf.dir/hid_macos.cc.o.d -o CMakeFiles/libdmrconf.dir/hid_macos.cc.o -c /tmp/qdmr-20230618-35854-12ga0el/lib/hid_macos.cc
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/ranges.cc:1:
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/ranges.hh:5:
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:48:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromMilliseconds(unsigned long long ms) {          ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:49:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(ms);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:51:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromSeconds(unsigned long long s) {                ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:52:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(s*1000ULL);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:54:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromMinutes(unsigned long long min) {              ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:55:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(min*60000ULL);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
[ 22%] Building CXX object lib/CMakeFiles/libdmrconf.dir/dfu_libusb.cc.o
cd /tmp/qdmr-20230618-35854-12ga0el/lib && /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_POSITIONING_LIB -DQT_SERIALPORT_LIB -DQT_WIDGETS_LIB -Dlibdmrconf_EXPORTS -F/usr/local/opt/qt@5/lib -I/usr/local/opt/qt@5/lib/QtWidgets.framework/Headers -I/usr/local/opt/qt@5/lib/QtGui.framework/Headers -I/usr/local/opt/qt@5/include/QtUiTools -I/usr/local/include/libusb-1.0 -I/tmp/qdmr-20230618-35854-12ga0el/src -I/tmp/qdmr-20230618-35854-12ga0el/lib -isystem /usr/local/opt/qt@5/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt@5/./mkspecs/macx-clang -isystem /usr/local/opt/qt@5/lib/QtNetwork.framework/Headers -isystem /usr/local/opt/qt@5/lib/QtSerialPort.framework/Headers -isystem /usr/local/opt/qt@5/lib/QtPositioning.framework/Headers -Wall -Wsign-compare -O3 -DNDEBUG -O3 -Wextra -std=gnu++14 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -fPIC -fPIC -MD -MT lib/CMakeFiles/libdmrconf.dir/dfu_libusb.cc.o -MF CMakeFiles/libdmrconf.dir/dfu_libusb.cc.o.d -o CMakeFiles/libdmrconf.dir/dfu_libusb.cc.o -c /tmp/qdmr-20230618-35854-12ga0el/lib/dfu_libusb.cc
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/interval.cc:1:
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:48:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromMilliseconds(unsigned long long ms) {          ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:49:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(ms);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:51:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromSeconds(unsigned long long s) {                ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:52:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(s*1000ULL);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:54:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromMinutes(unsigned long long min) {              ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:55:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(min*60000ULL);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
3 errors generated.
make[2]: *** [lib/CMakeFiles/libdmrconf.dir/ranges.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/radio.cc:1:
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/radio.hh:14:
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/codeplug.hh:8:
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/config.hh:44:
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/contact.hh:8:
In file included from /tmp/qdmr-20230618-35854-12ga0el/lib/anytone_extension.hh:8:
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:48:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromMilliseconds(unsigned long long ms) {          ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:49:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(ms);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:51:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromSeconds(unsigned long long s) {                ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:52:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(s*1000ULL);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:54:36: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  static inline constexpr Interval fromMinutes(unsigned long long min) {              ///< Unit conversion.
                                   ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:55:12: note: non-constexpr constructor 'Interval' cannot be used in a constant expression
    return Interval(min*60000ULL);
           ^
/tmp/qdmr-20230618-35854-12ga0el/lib/interval.hh:30:3: note: declared here
  Interval(const Interval &other);
  ^
3 errors generated.
make[2]: *** [lib/CMakeFiles/libdmrconf.dir/interval.cc.o] Error 1
3 errors generated.
make[2]: *** [lib/CMakeFiles/libdmrconf.dir/radio.cc.o] Error 1
make[1]: *** [lib/CMakeFiles/libdmrconf.dir/all] Error 2
make: *** [all] Error 2

Building with:

% clang -v
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

% cmake --version
cmake version 3.26.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

% make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
@hmatuschek hmatuschek self-assigned this Jun 19, 2023
@hmatuschek hmatuschek added the bug Something isn't working label Jun 19, 2023
@hmatuschek hmatuschek linked a pull request Jun 19, 2023 that will close this issue
@hmatuschek hmatuschek removed a link to a pull request Jun 19, 2023
@hmatuschek
Copy link
Owner

Seems to be fixed in branch fix-clang-compiler-issue. Also added a CI workflow to check with clang-14. This issue will be closed automatically, once I merge that branch. Feel free to reopen it, if there are sill issues.

hmatuschek added a commit that referenced this issue Jun 19, 2023
* Added Workflow for clang-14 build.
* Fixed Interval copy constructor. Addresses #344.
@toco
Copy link
Author

toco commented Jun 19, 2023

Thank you for the very quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants