This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/81912] New: std::distance not constexpr in C++17 mode


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81912

            Bug ID: 81912
           Summary: std::distance not constexpr in C++17 mode
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at hazardy dot de
  Target Milestone: ---

Created attachment 42018
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42018&action=edit
The test file.

Although std::distance is marked with _GLIBCXX17_CONSTEXPR the called
std::__iterator_category is not and thus std::distance can not be called in a
constexpr environment.

Tested with MinGW 7.1 on Windows and GCC 7.1 and 7.2 on godbolt [1]. The only
parameter used is -std=c++1z.

[1] https://godbolt.org/g/87Edtw

$ g++ -v
Using built-in specs.
COLLECT_GCC=E:\MinGW64\bin\g++.exe
COLLECT_LTO_WRAPPER=E:/MinGW64/bin/../libexec/gcc/x86_64-w64-mingw32/7.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-7.1.0/configure --host=x86_64-w64-mingw32
--build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64
--with-sysroot=/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64
--enable-shared --enable-static --disable-multilib
--enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes
--enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto
--enable-graphite --enable-checking=release --enable-fully-dynamic-string
--enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes
--disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap
--disable-rpath --disable-win32-registry --disable-nls --disable-werror
--disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona
--with-tune=core2 --with-libiconv --with-system-zlib
--with-gmp=/c/mingw710/prerequisites/x86_64-w64-mingw32-static
--with-mpfr=/c/mingw710/prerequisites/x86_64-w64-mingw32-static
--with-mpc=/c/mingw710/prerequisites/x86_64-w64-mingw32-static
--with-isl=/c/mingw710/prerequisites/x86_64-w64-mingw32-static
--with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project'
--with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe
-fno-ident -I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/include
-I/c/mingw710/prerequisites/x86_64-zlib-static/include
-I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2
-pipe -fno-ident
-I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/include
-I/c/mingw710/prerequisites/x86_64-zlib-static/include
-I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS='
-I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/include
-I/c/mingw710/prerequisites/x86_64-zlib-static/include
-I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe
-fno-ident -L/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/lib
-L/c/mingw710/prerequisites/x86_64-zlib-static/lib
-L/c/mingw710/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 7.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

$ g++ -std=c++1z test.cpp
test.cpp: In function 'int main()':
test.cpp:6:5: error: non-constant condition for static assertion
     static_assert(std::distance(a.begin(), a.end()) == 2);
     ^~~~~~~~~~~~~
test.cpp:6:32: error: 'constexpr typename
std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator,
_InputIterator) [with _InputIterator = int*; typename
std::iterator_traits<_Iterator>::difference_type = long long int]' called in a
constant expression
     static_assert(std::distance(a.begin(), a.end()) == 2);
                   ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from
E:/MinGW64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/bits/stl_algobase.h:66:0,
                 from
E:/MinGW64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/algorithm:61,
                 from test.cpp:1:
E:/MinGW64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/bits/stl_iterator_base_funcs.h:138:5:
note: 'constexpr typename std::iterator_traits<_Iterator>::difference_type
std::distance(_InputIterator, _InputIterator) [with _InputIterator = int*;
typename std::iterator_traits<_Iterator>::difference_type = long long int]' is
not usable as a constexpr function because:
     distance(_InputIterator __first, _InputIterator __last)
     ^~~~~~~~
E:/MinGW64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/bits/stl_iterator_base_funcs.h:142:33:
error: call to non-constexpr function 'typename
std::iterator_traits<_Iterator>::iterator_category
std::__iterator_category(const _Iter&) [with _Iter = int*; typename
std::iterator_traits<_Iterator>::iterator_category =
std::random_access_iterator_tag]'
         std::__iterator_category(__first));
         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]