public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97591] New: Segmentation fault by non-type template parameters
@ 2020-10-27 14:10 v.stiff at gmail dot com
  2020-10-27 14:10 ` [Bug c++/97591] " v.stiff at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: v.stiff at gmail dot com @ 2020-10-27 14:10 UTC (permalink / raw)
  To: gcc-bugs

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<Slug<Path()>, Rest...> {
 | ^

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/97591] Segmentation fault by non-type template parameters
  2020-10-27 14:10 [Bug c++/97591] New: Segmentation fault by non-type template parameters v.stiff at gmail dot com
@ 2020-10-27 14:10 ` v.stiff at gmail dot com
  2020-10-27 14:11 ` v.stiff at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: v.stiff at gmail dot com @ 2020-10-27 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Vladimir Meremyanin <v.stiff at gmail dot com> ---
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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/97591] Segmentation fault by non-type template parameters
  2020-10-27 14:10 [Bug c++/97591] New: Segmentation fault by non-type template parameters v.stiff at gmail dot com
  2020-10-27 14:10 ` [Bug c++/97591] " v.stiff at gmail dot com
@ 2020-10-27 14:11 ` v.stiff at gmail dot com
  2020-10-27 14:21 ` mpolacek at gcc dot gnu.org
  2020-10-27 15:07 ` v.stiff at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: v.stiff at gmail dot com @ 2020-10-27 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Vladimir Meremyanin <v.stiff at gmail dot com> ---
Program source:


// /usr/local/Cellar/gcc/10.2.0/bin/g++-10 -std=c++20 type-level-routes.cpp

#include <iostream>
#include <string>

// FixedString from
https://www.reddit.com/r/cpp/comments/bhxx49/c20_string_literals_as_nontype_template/
template<unsigned N>
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<unsigned N> FixedString(char const (&)[N]) -> FixedString<N - 1>;

// own code

// Static url part
template <FixedString Path>
struct Slug {
  static constexpr char const* path = Path;
};

// Dynamic url part
template <typename Value>
struct Capture {
  using value_t = Value;
};

// Route
template <typename... Args>
struct Route;

template<typename ValueT, typename... Rest>
struct Route<Capture<ValueT>, Rest...> {

  static std::string toString(ValueT value, auto... rest) {
    return "/" + std::to_string(value) + Route<Rest...>::toString(rest...);
  }

};

template<FixedString Path, typename... Rest>
struct Route<Slug<Path()>, Rest...> {       /* <------- Path() here causes
compiler segfault */

  static std::string toString(auto... rest) {
    return "/" + std::string(SlugT::path) + Route<Rest...>::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> >;

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/97591] Segmentation fault by non-type template parameters
  2020-10-27 14:10 [Bug c++/97591] New: Segmentation fault by non-type template parameters v.stiff at gmail dot com
  2020-10-27 14:10 ` [Bug c++/97591] " v.stiff at gmail dot com
  2020-10-27 14:11 ` v.stiff at gmail dot com
@ 2020-10-27 14:21 ` mpolacek at gcc dot gnu.org
  2020-10-27 15:07 ` v.stiff at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-27 14:21 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mpolacek at gcc dot gnu.org
         Resolution|---                         |DUPLICATE

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looks like a dup.

*** This bug has been marked as a duplicate of bug 95291 ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/97591] Segmentation fault by non-type template parameters
  2020-10-27 14:10 [Bug c++/97591] New: Segmentation fault by non-type template parameters v.stiff at gmail dot com
                   ` (2 preceding siblings ...)
  2020-10-27 14:21 ` mpolacek at gcc dot gnu.org
@ 2020-10-27 15:07 ` v.stiff at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: v.stiff at gmail dot com @ 2020-10-27 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Vladimir Meremyanin <v.stiff at gmail dot com> ---
Maybe but in the #95291 crash occurs when access member, and here when
operator() is called. So probably both issues have a single cause.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-27 15:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 14:10 [Bug c++/97591] New: Segmentation fault by non-type template parameters v.stiff at gmail dot com
2020-10-27 14:10 ` [Bug c++/97591] " v.stiff at gmail dot com
2020-10-27 14:11 ` v.stiff at gmail dot com
2020-10-27 14:21 ` mpolacek at gcc dot gnu.org
2020-10-27 15:07 ` v.stiff at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).