Skip to content

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

@mumbleskates

Description

@mumbleskates

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;
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions