[Bug c++/82218] [C++1x] constexpr on static member function causes segfault

2017-10-27 Thread paolo.carlini at oracle dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82218

Paolo Carlini  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |7.0

--- Comment #5 from Paolo Carlini  ---
Fixed in 7.1.0. I added a version of Jakub's testcase not using includes.

[Bug c++/82218] [C++1x] constexpr on static member function causes segfault

2017-10-27 Thread paolo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82218

--- Comment #4 from paolo at gcc dot gnu.org  ---
Author: paolo
Date: Fri Oct 27 23:14:43 2017
New Revision: 254189

URL: https://gcc.gnu.org/viewcvs?rev=254189=gcc=rev
Log:
2017-10-27  Paolo Carlini  

PR c++/82218
* g++.dg/cpp1y/constexpr-82218.C: New.

Added:
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-82218.C
Modified:
trunk/gcc/testsuite/ChangeLog

[Bug c++/82218] [C++1x] constexpr on static member function causes segfault

2017-09-15 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82218

Jakub Jelinek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-09-15
 Ever confirmed|0   |1

--- Comment #3 from Jakub Jelinek  ---
Oh, and the testcase is:
#include 

template < typename T >
class delegate;

template < typename R, typename... Params >
class delegate< R(Params...) > final
{
private:
  using CallbackType = R (*)(void*, Params...);

  using FunctionPtr = R (*)(Params...);

  template < typename Object >
  using MethodPtr = R (Object::*)(Params...);

  template < typename Object >
  using ConstMethodPtr = R (Object::*)(Params...) const;

  void* obj_;
  CallbackType cb_;

  template < typename Object, MethodPtr< Object > Mptr >
  constexpr static R invoke_method(void* obj, Params... params) noexcept(
  noexcept((static_cast< Object* >(obj)->*Mptr)(params...)))
  {
return (static_cast< Object* >(obj)->*Mptr)(params...);
  }

  template < typename Object, ConstMethodPtr< Object > Mptr >
  constexpr static R invoke_method(void* obj, Params... params) noexcept(
  noexcept((static_cast< Object* >(obj)->*Mptr)(params...)))
  {
return (static_cast< Object* >(obj)->*Mptr)(params...);
  }

  template < FunctionPtr Fptr >
  constexpr static R invoke_function(void*, Params... params) noexcept(
  noexcept((*Fptr)(params...)))
  {
return (*Fptr)(params...);
  }

  constexpr delegate(void* obj, CallbackType callback) noexcept : obj_(obj),
  cb_(callback)
  {
  }

  constexpr static R error_function(Params...)
  {
while(1);
  }

public:
  using base_type = delegate< R(Params...) >;

  delegate()
  {
*this = from< error_function >();
  }

  delegate(const base_type&) = default;
  delegate(base_type&&)  = default;

  base_type& operator=(const base_type&)  = default;
  base_type& operator=(base_type&&)   = default;

  template < typename Object, MethodPtr< Object > Mptr >
  constexpr static auto from(Object& obj) noexcept
  {
return delegate(, _method< Object, Mptr >);
  }

  template < typename Object, ConstMethodPtr< Object > Mptr >
  constexpr static auto from(Object& obj) noexcept
  {
return delegate(, _method< Object, Mptr >);
  }

  template < FunctionPtr Fptr >
  constexpr static auto from() noexcept
  {
static_assert(Fptr != nullptr, "Function pointer must not be null");

return delegate(nullptr, _function< Fptr >);
  }

  template < typename... Args >
  constexpr auto operator()(Args&&... params) const
  noexcept(noexcept((*cb_)(obj_, std::forward< Args >(params)...)))
  {
return (*cb_)(obj_, std::forward< Args >(params)...);
  }

  constexpr bool valid() const noexcept
  {
return (cb_ != _function< error_function >);
  }

  constexpr bool operator==(const delegate& other) const noexcept
  {
return (obj_ == other.obj_) && (cb_ == other.cb_);
  }

  constexpr bool operator!=(const delegate& other) const noexcept
  {
return (obj_ != other.obj_) || (cb_ != other.cb_);
  }
};

delegate< void(void) > a;

void test()
{
  a();
}

The problem is probably the constexpr function with while(1); in it.

[Bug c++/82218] [C++1x] constexpr on static member function causes segfault

2017-09-15 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82218

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||jason at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
ICEs on x86_64-linux too.  With r235218 we started to hang instead, and with
r238730 aka PR65970 it finally compiles.
Dunno if any of those two are backportable.

[Bug c++/82218] [C++1x] constexpr on static member function causes segfault

2017-09-15 Thread emil.fresk at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82218

--- Comment #1 from Emil Fresk  ---
Moreover, if one changes so Params... type-pack is not void it also compiles
fine. The use of void seems to be the part causing the problem.

This can be tested by changing void(void) to void(int) on line 134, and adding
an argument to a(), on line 138, for example a(10).