在 2019/1/14 上午6:46, Maarten Verhage 写道: > Hi all, > > I might have found a bug in gcc or mingw, but I'm not really sure. >
Generally: This program contains no mingw-w64-specific thing, so it is less likely to be a mingw-w64 issue. You should have sent this to the gcc-help mailing list which is more appropriate. > For the following version: > g++ (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0 > > A short example: > > #include <cstddef> > #include <cstdio> > #include <cstdint> > #include <array> > > int main() > { > const char istr[] = "Hello"; > std::array<char16_t, std::char_traits<char>::length( istr )> str16; > > return 0; > } > > Now the compile step: > > g++ -c -std=c++17 -pedantic -Wextra -Wlogical-op test.cpp > In file included from > C:/dev/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/string:40, > from > C:/dev/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/stdexcept:39, > from > C:/dev/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/array:39, > from test.cpp:4: > C:/dev/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h: > > In function 'int main()': > test.cpp:9:54: in 'constexpr' expansion of > 'std::char_traits<char>::length(((const char*)(& istr)))' > C:/dev/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:320:25: > > error: '__builtin_strlen(((const char_type*)(& istr)))' is not a constant > expression > return __builtin_strlen(__s); > ~~~~~~~~~~~~~~~~^~~~~ > test.cpp:9:54: note: in template argument for type 'long long unsigned int' > std::array<char16_t, std::char_traits<char>::length( istr )> str16; > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~ > mingw32-make.exe: *** [C:\dev\mydesign\SW\C++\win32\array_test\test.mak:9: > test.o] Error 1 > > This shouldn't be, right? As it succesfully selects the constexpr function > variant for the second template argument it should also work further down, I > believe. > Your code is not valid. Clang++ rejects your snippet, too. The array-to-pointer conversion from an array of `const char` is not allowed in a constant expression unless such an array is declared with `constexpr` [1]. Use `constexpr` in place of `const` will solve your problem. [1] ISO/IEC WG21 N4762: 7.7 Constant expressions [expr.const], (2.7), (2.7.1), (2.7.3). <http://eel.is/c++draft/expr.const#4.7> -- Best regards, LH_Mouse _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public