public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23585] New: mem_fun* code fine with -O1, bus error with -O2
@ 2005-08-26 22:14 matti dot rintala at iki dot fi
  2005-08-26 22:16 ` [Bug c++/23585] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: matti dot rintala at iki dot fi @ 2005-08-26 22:14 UTC (permalink / raw)
  To: gcc-bugs

The following code (definitions of mem_fun* taken from <functional>) works fine
when compiled with -O1, but causes a bus error crash when compiled with -O2.

--------------------
// Templates taken from <functional>
template <class _Ret, class _Tp>
class const_mem_fun_t
{
public:
  explicit
  const_mem_fun_t(_Ret (_Tp::*__pf)() const)
    : _M_f(__pf) {}
  
  _Ret
  operator()(const _Tp* __p) const
  { return (__p->*_M_f)(); }
private:
  _Ret (_Tp::*_M_f)() const;
};

template <class _Ret, class _Tp>
class const_mem_fun_ref_t
{
public:
  explicit
  const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
    : _M_f(__pf) {}
  
  _Ret
  operator()(const _Tp& __r) const
  { return (__r.*_M_f)(); }
private:
  _Ret (_Tp::*_M_f)() const;
};

template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_t
{
public:
  explicit
  const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
    : _M_f(__pf) {}
  
  _Ret
  operator()(const _Tp* __p, _Arg __x) const
  { return (__p->*_M_f)(__x); }
private:
  _Ret (_Tp::*_M_f)(_Arg) const;
};


template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_ref_t
{
public:
  explicit
  const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
    : _M_f(__pf) {}
  
  _Ret
  operator()(const _Tp& __r, _Arg __x) const
  { return (__r.*_M_f)(__x); }
private:
  _Ret (_Tp::*_M_f)(_Arg) const;
};

template <class _Ret, class _Tp>
inline const_mem_fun_t<_Ret, _Tp>
mem_fun(_Ret (_Tp::*__f)() const)
{ return const_mem_fun_t<_Ret, _Tp>(__f); }

template <class _Ret, class _Tp>
inline const_mem_fun_ref_t<_Ret, _Tp>
mem_fun_ref(_Ret (_Tp::*__f)() const)
{ return const_mem_fun_ref_t<_Ret, _Tp>(__f); }

template <class _Ret, class _Tp, class _Arg>
inline const_mem_fun1_t<_Ret, _Tp, _Arg>
mem_fun(_Ret (_Tp::*__f)(_Arg) const)
{ return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }

template <class _Ret, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
{ return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }

class Class {
public:
  void vf0c() const;
  void vf1c(const int&) const;
};

int main()
{
  Class obj;
  const Class& objc = obj;

  mem_fun(&Class::vf0c)(&objc);
  mem_fun(&Class::vf1c)(&objc, 1);

  mem_fun_ref(&Class::vf0c)(objc);
  mem_fun_ref(&Class::vf1c)(objc, 1);
}

void Class::vf0c() const
{}

void Class::vf1c(const int&) const
{}

-- 
           Summary: mem_fun* code fine with -O1, bus error with -O2
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matti dot rintala at iki dot fi
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23585


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

* [Bug c++/23585] mem_fun* code fine with -O1, bus error with -O2
  2005-08-26 22:14 [Bug c++/23585] New: mem_fun* code fine with -O1, bus error with -O2 matti dot rintala at iki dot fi
@ 2005-08-26 22:16 ` pinskia at gcc dot gnu dot org
  2005-08-27 22:12 ` pinskia at gcc dot gnu dot org
  2005-08-27 22:16 ` [Bug middle-end/23585] " pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-26 22:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-26 22:14 -------
I think this has already been fixed in 4.0.2 but I have not tested it.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23585


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

* [Bug c++/23585] mem_fun* code fine with -O1, bus error with -O2
  2005-08-26 22:14 [Bug c++/23585] New: mem_fun* code fine with -O1, bus error with -O2 matti dot rintala at iki dot fi
  2005-08-26 22:16 ` [Bug c++/23585] " pinskia at gcc dot gnu dot org
@ 2005-08-27 22:12 ` pinskia at gcc dot gnu dot org
  2005-08-27 22:16 ` [Bug middle-end/23585] " pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-27 22:12 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23585


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

* [Bug middle-end/23585] mem_fun* code fine with -O1, bus error with -O2
  2005-08-26 22:14 [Bug c++/23585] New: mem_fun* code fine with -O1, bus error with -O2 matti dot rintala at iki dot fi
  2005-08-26 22:16 ` [Bug c++/23585] " pinskia at gcc dot gnu dot org
  2005-08-27 22:12 ` pinskia at gcc dot gnu dot org
@ 2005-08-27 22:16 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-27 22:16 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end
           Keywords|                            |wrong-code


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23585


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

end of thread, other threads:[~2005-08-27 22:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-26 22:14 [Bug c++/23585] New: mem_fun* code fine with -O1, bus error with -O2 matti dot rintala at iki dot fi
2005-08-26 22:16 ` [Bug c++/23585] " pinskia at gcc dot gnu dot org
2005-08-27 22:12 ` pinskia at gcc dot gnu dot org
2005-08-27 22:16 ` [Bug middle-end/23585] " pinskia at gcc dot gnu dot org

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).