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

constexpr does not imply const in c++14 #105

Closed
mumbleskates opened this issue Sep 14, 2021 · 4 comments
Closed

constexpr does not imply const in c++14 #105

mumbleskates opened this issue Sep 14, 2021 · 4 comments

Comments

@mumbleskates
Copy link
Contributor

OS: ubuntu 21.04
compiler: clang-14 nightly

fast_float::span<T>::len() is marked constexpr but not const, and the compiler emits a fatal warning in the default build.

commands:

mkdir build && cd build
cmake -DFASTFLOAT_TEST=ON ..
cmake --build . --verbose

error:

[ 11%] Building CXX object tests/CMakeFiles/basictest.dir/basictest.cpp.o
cd /home/widders/repos/fast_float/build/tests && /usr/bin/c++ -DSUPPLEMENTAL_TEST_DATA_DIR=\"/home/widders/repos/fast_float/build/_deps/supplemental_test_files-build/data\" -I/home/widders/repos/fast_float/include -I/home/widders/repos/fast_float/build/_deps/doctest-src -O3 -DNDEBUG -Werror -Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion -std=gnu++11 -o CMakeFiles/basictest.dir/basictest.cpp.o -c /home/widders/repos/fast_float/tests/basictest.cpp
In file included from /home/widders/repos/fast_float/tests/basictest.cpp:5:
In file included from /home/widders/repos/fast_float/include/fast_float/fast_float.h:77:
In file included from /home/widders/repos/fast_float/include/fast_float/parse_number.h:4:
In file included from /home/widders/repos/fast_float/include/fast_float/ascii_number.h:18:
/home/widders/repos/fast_float/include/fast_float/float_common.h:127:20: error: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior [-Werror,-Wconstexpr-not-const]
  constexpr size_t len() noexcept {
                   ^
                         const
1 error generated.

fix:

diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h
--- a/include/fast_float/float_common.h	(revision 1b9150913e07bc199ea7bc25fc1609a748bd301c)
+++ b/include/fast_float/float_common.h	(date 1631605731861)
@@ -124,7 +124,7 @@
   span(const T* _ptr, size_t _length) : ptr(_ptr), length(_length) {}
   span() : ptr(nullptr), length(0) {}
 
-  constexpr size_t len() noexcept {
+  constexpr size_t len() const noexcept {
     return length;
   }
@lemire
Copy link
Member

lemire commented Sep 14, 2021

This was supposedly fixed in a commit, but I made a mistake. I will create a patch release soon. Thank you.

@lemire
Copy link
Member

lemire commented Sep 15, 2021

Fixed in release 3.1.

The fix is just as you suggested.

@lemire lemire closed this as completed Sep 15, 2021
@mumbleskates
Copy link
Contributor Author

Thanks!

@lemire
Copy link
Member

lemire commented Sep 15, 2021

Thanks to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants