lamarrr/STX

compiler error on clang: defaulted definition of move assignment operator is not constexpr

bgschiller opened this issue · 1 comments

Describe the bug
Upon freshly cloning the repo, I am unable to build the software. Here are the steps I take

➜ git clone https://github.com/lamarrr/stx.git && cd stx 
➜ mkdir build && cd build
➜ cmake ..
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at CMakeLists.txt:48 (message):
  [STX] STX requires at least C++ 17 but 'CMAKE_CXX_STANDARD' was not set.
  'CMAKE_CXX_STANDARD' will be set to 17 (C++ 17).  Set 'CMAKE_CXX_STANDARD'
  to 17 (C++ 17) or later standards to silence this warning


-- [STX] Build as a shared library: OFF
-- [STX] Build tests: OFF
-- [STX] Enable debug mode assertions: OFF
-- [STX] Build documentation: OFF
-- [STX] Build benchmarks: OFF
-- [STX] Build sanitized tests: OFF
-- [STX] Override panic handler: OFF
-- [STX] Make runtime panic hook visible: OFF
-- [STX] Enable backtrace: OFF
-- [STX] Enable panic backtrace: OFF
-- Performing Test LIBSTX_SUPPORTS_WPEDANTIC_FLAG
-- Performing Test LIBSTX_SUPPORTS_WPEDANTIC_FLAG - Success
-- Performing Test LIBSTX_SUPPORTS_WALL_FLAG
-- Performing Test LIBSTX_SUPPORTS_WALL_FLAG - Success
-- Performing Test LIBSTX_SUPPORTS_WEXTRA_FLAG
-- Performing Test LIBSTX_SUPPORTS_WEXTRA_FLAG - Success
-- Performing Test LIBSTX_SUPPORTS_WNO_UNUSED_RESULT_FLAG
-- Performing Test LIBSTX_SUPPORTS_WNO_UNUSED_RESULT_FLAG - Success
-- Performing Test LIBSTX_SUPPORTS_WNO_UNUSED_VARIABLE_FLAG
-- Performing Test LIBSTX_SUPPORTS_WNO_UNUSED_VARIABLE_FLAG - Success
-- Performing Test LIBSTX_HAS_STD_THREAD_MUTEX
-- Performing Test LIBSTX_HAS_STD_THREAD_MUTEX - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/brian/code/stx/build
➜  make
Scanning dependencies of target stx
[ 33%] Building CXX object CMakeFiles/stx.dir/src/panic/hook.cc.o
In file included from /Users/brian/code/stx/src/panic/hook.cc:30:
In file included from /Users/brian/code/stx/include/stx/panic/hook.h:34:
In file included from /Users/brian/code/stx/include/stx/panic.h:32:
/Users/brian/code/stx/include/stx/report.h:162:3: error: defaulted definition of
      copy assignment operator is not constexpr
  constexpr FixedReport& operator=(FixedReport const&) noexcept = default;
  ^
/Users/brian/code/stx/include/stx/report.h:163:3: error: defaulted definition of
      move assignment operator is not constexpr
  constexpr FixedReport& operator=(FixedReport&&) noexcept = default;
  ^
/Users/brian/code/stx/include/stx/report.h:286:3: error: defaulted definition of
      copy assignment operator is not constexpr
  constexpr SpanReport& operator=(SpanReport const&) noexcept = default;
  ^
/Users/brian/code/stx/include/stx/report.h:287:3: error: defaulted definition of
      move assignment operator is not constexpr
  constexpr SpanReport& operator=(SpanReport&&) noexcept = default;
  ^
/Users/brian/code/stx/include/stx/report.h:313:3: error: defaulted definition of
      copy assignment operator is not constexpr
  constexpr ReportPayload& operator=(ReportPayload const&) noexcept = default;
  ^
/Users/brian/code/stx/include/stx/report.h:314:3: error: defaulted definition of
      move assignment operator is not constexpr
  constexpr ReportPayload& operator=(ReportPayload&&) noexcept = default;
  ^
In file included from /Users/brian/code/stx/src/panic/hook.cc:30:
In file included from /Users/brian/code/stx/include/stx/panic/hook.h:34:
In file included from /Users/brian/code/stx/include/stx/panic.h:33:
/Users/brian/code/stx/include/stx/source_location.h:89:3: error: defaulted
      definition of copy assignment operator is not constexpr
  constexpr SourceLocation& operator=(SourceLocation const& other) noexcept =
  ^
/Users/brian/code/stx/include/stx/source_location.h:91:3: error: defaulted
      definition of move assignment operator is not constexpr
  constexpr SourceLocation& operator=(SourceLocation&& other) noexcept =
  ^
8 errors generated.
make[2]: *** [CMakeFiles/stx.dir/src/panic/hook.cc.o] Error 1
make[1]: *** [CMakeFiles/stx.dir/all] Error 2
make: *** [all] Error 2

I noticed that the same behavior occurs if I pass the cmake options used in the macos CI script and also if I use the v1.0.1 tagged version.

Expected behavior

I expected the build to succeed without errors.

Desktop (please complete the following information):

  • OS: MacOS 10.14.6
  • Cmake: 3.19.3
➜  g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Hi, thanks for filing this. This seems to be a compiler bug as mentioned here: https://stackoverflow.com/questions/55182242/declaring-defaulted-assignment-operator-as-constexpr-which-compiler-is-right.

However, I'll set up a PR to remove defaulted constructors as they are unnecessary in most cases. I hope that'd make your compiler accept it