[Bug c++/97591] New: Segmentation fault by non-type template parameters
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97591 Bug ID: 97591 Summary: Segmentation fault by non-type template parameters Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: v.stiff at gmail dot com Target Milestone: --- I was experimenting with new C++20 features and stumbled on segfault in GCC 10.2.0: type-level-routes.cpp:45:25: internal compiler error: Segmentation fault: 11 45 | struct Route, Rest...> { | ^
[Bug c++/97591] Segmentation fault by non-type template parameters
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97591 --- Comment #1 from Vladimir Meremyanin --- g++-10 -v Using built-in specs. COLLECT_GCC=/usr/local/Cellar/gcc/10.2.0/bin/g++-10 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/10.2.0/libexec/gcc/x86_64-apple-darwin19/10.2.0/lto-wrapper Target: x86_64-apple-darwin19 Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/10.2.0 --libdir=/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 10.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SED=/usr/bin/sed Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.2.0 (Homebrew GCC 10.2.0)
[Bug c++/97591] Segmentation fault by non-type template parameters
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97591 --- Comment #2 from Vladimir Meremyanin --- Program source: // /usr/local/Cellar/gcc/10.2.0/bin/g++-10 -std=c++20 type-level-routes.cpp #include #include // FixedString from https://www.reddit.com/r/cpp/comments/bhxx49/c20_string_literals_as_nontype_template/ template struct FixedString { char buf[N + 1]{}; constexpr FixedString(char const* s) { for (unsigned i = 0; i != N; ++i) buf[i] = s[i]; } constexpr operator char const*() const { return buf; } }; template FixedString(char const (&)[N]) -> FixedString; // own code // Static url part template struct Slug { static constexpr char const* path = Path; }; // Dynamic url part template struct Capture { using value_t = Value; }; // Route template struct Route; template struct Route, Rest...> { static std::string toString(ValueT value, auto... rest) { return "/" + std::to_string(value) + Route::toString(rest...); } }; template struct Route, Rest...> { /* <--- Path() here causes compiler segfault */ static std::string toString(auto... rest) { return "/" + std::string(SlugT::path) + Route::toString(rest...); } }; template <> struct Route<> { static std::string toString() { return ""; } }; using BlogRoot = Route< "blog" >; using AllPosts = Route< "blog", "posts" >; using SinglePost = Route< "blog", "posts", Capture >; int main() { // /blog std::cout << "blog = " << BlogRoot::toString() << std::endl; // /blog/posts std::cout << "allPosts = " << AllPosts::toString() << std::endl; // invalid path, compilation error // std::cout << "singlePost = " << SinglePost::toString() << std::endl; // /blog/posts/42 std::cout << "singlePost = " << SinglePost::toString(42) << std::endl; return 0; }
[Bug c++/97591] Segmentation fault by non-type template parameters
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97591 --- Comment #4 from Vladimir Meremyanin --- Maybe but in the #95291 crash occurs when access member, and here when operator() is called. So probably both issues have a single cause.