[Bug c++/51571] No named return value optimization while adding a dummy scope

2013-06-02 Thread guillaume.melquiond at inria dot fr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51571

Guillaume Melquiond  changed:

   What|Removed |Added

 CC||guillaume.melquiond at inria 
dot f
   ||r

--- Comment #3 from Guillaume Melquiond  
---
I have recently encountered a similar problem, but in a much more general case.

struct A {
A(int);
A(A const &);
~A();
};

A f(bool b)
{
if (b) return A(0);
A a(1);
return a;
}

All the return statements dominated by variable "a" return "a", so its
construction should happen in-place, hence eliding copy-construction and
destruction. Unfortunately, this is not what happens with g++ 4.8.0.

Interestingly enough, if one uninlines the code by hand, g++ actually generates
the optimal code, so it is possible though cumbersome to work around the missed
optimization:

inline A f2()
{
A a(1);
return a;
}

A f1(bool b)
{
if (b) return A(0);
return f2();
}

produces

A f1(bool) (bool b)
{
  :
  if (b_2(D) != 0)
goto ;
  else
goto ;

  :
  A::A (_4(D), 0);
  goto ;

  :
  A::A (_4(D), 1);

  :
  return _4(D);
}


[Bug c++/27336] "this" pointer is not assumed to be not null

2016-08-19 Thread guillaume.melquiond at inria dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27336

--- Comment #8 from Guillaume Melquiond  
---
It is partly fixed. In callee position, GCC now knows that "this" is non-null.
But in caller position, GCC still cannot make use of that information to remove
non-null checks from dynamic casts. The following testcase is still relevant.

struct A { void g(); };
bool f(A *a) {
  a->g();
  return a;
}