[Bug c++/59070] New: Captured object is being moved from the lambda on returning it.

2013-11-10 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59070

Bug ID: 59070
   Summary: Captured object is being moved from the lambda on
returning it.
   Product: gcc
   Version: 4.8.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: sir_nawaz959 at yahoo dot com

I'm using GCC 4.8.1

Here is the code which reproduces this bug:

   std::vectorstd::string items {default};

   auto add = [=](std::string item) mutable 
  { items.push_back(item); return items; };

   std::cout  add(one)  std::endl;
   std::cout  add(two)  std::endl;
   std::cout  add(three)  std::endl;

Imagine that operator is overloaded for std::vector which all items on ONE
line. The expected out is:

   default one 
   default one two 
   default one two three

But it actually outputs this:

   default one 
   two 
   three

So it seems on the first return, the captured vector is moved. 

However, if I define the lambda as:

   auto add = [=](std::string item) mutable 
  { items.push_back(item); auto  x = items; return x; } ;

OR as:

   auto add = [=](std::string item) mutable 
  { auto  x= items; x.push_back(item); return x; } ;


It prints the expected output.


[Bug c++/59070] Captured object is being moved from the lambda on returning it.

2013-11-10 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59070

Sarfaraz Nawaz sir_nawaz959 at yahoo dot com changed:

   What|Removed |Added

 Status|RESOLVED|NEW
 Resolution|WORKSFORME  |---

--- Comment #4 from Sarfaraz Nawaz sir_nawaz959 at yahoo dot com ---
Here is the complete testcase which compiles fine but gives incorrect output:




#include iostream
#include vector
#include string

std::ostream  operator(std::ostream  out, std::vectorstd::string const 
items)
{
for(auto const  item : items ) 
out  item   ;
return out;
}

int main() 
{
std::cout  \nGCC   __VERSION__  std::endl;

std::vectorstd::string items {default};

auto add = [=](std::string item) mutable { items.push_back(item); return
items; } ;

std::cout  add(one)  std::endl;
std::cout  add(two)  std::endl;
std::cout  add(three)  std::endl;
}

$ g++-4.8 -std=c++11 -O2 -Wall -pedantic-errors main.cpp  ./a.out

GCC 4.8.1
default one 
two 
three

which is incorrect output


[Bug c++/58924] New: Non-member invocation of overload of operator when the first argument is a temporary of type std::stringstream

2013-10-30 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58924

Bug ID: 58924
   Summary: Non-member invocation of overload of operator when
the first argument is a temporary of type
std::stringstream
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: sir_nawaz959 at yahoo dot com

I'm using GCC-4.8.1 in C++11 Mode.

Consider this code,

#include sstream
#include iostream

int main()
{
auto s = static_caststd::stringstream(std::stringstream()  XYZ 
ABC).str();

std::cout  s  std::endl;
}

Actual (incorrect) output:

XYZABC

The expected output is an address following by ABC, something like this:

0x400e83ABC


Because `std::stringstream()` is a temporary, so the first invocation of
`operator` must resolve to a member function (taking void* as argument) which
would print the address, and then the non-member function should be invoked for
the second ``.

Note that this works as expected when I don't use `-std=C++11` (of course, in
that case I use `std::string` instead of `auto`).


[Bug libstdc++/58924] Non-member invocation of overload of operator when the first argument is a temporary of type std::stringstream

2013-10-30 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58924

--- Comment #5 from Sarfaraz Nawaz sir_nawaz959 at yahoo dot com ---
(In reply to Fanael from comment #1)
 That's expected behavior AFAIU. 'operator(basic_ostreamcharT, traits
 os, const T x)' is a better match for const char[K] than
 'basic_ostreamcharT,traits basic_ostreamcharT,traits::operator(const
 void* p)', hence the former gets called, which then forwards the arguments
 to 'operator(basic_ostreamcharT, traits os, const charT* x)'.


Oh. I didn't come across this overload. Great that they've added this.

Invalid bug.


[Bug libstdc++/56336] New: Buggy implementation of stoi, stol, stoll

2013-02-14 Thread sir_nawaz959 at yahoo dot com


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



 Bug #: 56336

   Summary: Buggy implementation of stoi, stol, stoll

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: libstdc++

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: sir_nawaz...@yahoo.com





The following code-snippet should throw std::invalid_argument exception as per

the Standard, but they don't, instead they print `8978`:



//demo : http://stacked-crooked.com/view?id=4853f6694dc11f93ed9a687567e5166d

int main()

{

std::cout   std::stoi(8978xyz)  std::endl;  //invalid argument

std::cout   std::stol(8978xyz)  std::endl;  //invalid argument

std::cout   std::stoll(8978xyz)  std::endl; //invalid argument

}



The buggy part of the implementation is this:



   //file : /4.7.2/include/c++/ext/string_conversions.h 

   //line : 60-61

   //function : __stoa



   if (__endptr == __str)

  std::__throw_invalid_argument(__name);





Easy fix:



  if (__endptr != (__str + std::strlen(__str)) )

  std::__throw_invalid_argument(__name);



That should fix the bug. But it would be better to pass the length of the

string to the function. After all, `std::stoi` family takes the argument as

`std::string` which returns the size in O(1).


[Bug c++/52688] static local variable can accessed from local class of function template

2012-03-26 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688

--- Comment #6 from Sarfaraz Nawaz sir_nawaz959 at yahoo dot com 2012-03-26 
15:54:46 UTC ---
(In reply to comment #5)
 (In reply to comment #0)
  While gcc-4.5.1 compiles fine this code
 
 Are you sure? I get the same error with 4.1.2, 4.4.3, 4.5.2, 4.6.3 and 4.7.0
 
 4.5.2 compiles and links OK with optimisation enabled, but so do the other
 versions

I used ideone.com to compile it, which uses gcc-4.5.1 with -std=c++0x.

http://ideone.com/Y2vIF

I just noticed that though it compiles and links fine, but it doesn't print the
expected output. :|

Interestingly, when I remove `const` from the definition of the static local
variable, and then I attempt to change it from the local class, it then gives
error:

http://ideone.com/vvwRc

:-)


[Bug c++/52688] static local variable can accessed from local class of function template

2012-03-24 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688

--- Comment #3 from Sarfaraz Nawaz sir_nawaz959 at yahoo dot com 2012-03-24 
15:25:22 UTC ---
(In reply to comment #2)
 http://gcc.gnu.org/wiki/VerboseDiagnostics#missing_static_const_definition

Jonathan, that is a different case. A static (const or otherwise) member of a
class needs a definition in order to take its address, but the bug I reported
is not about static member of a class, rather it is about a static variable
local to a function template. Interestingly as I said, this code compiles fine
in gcc-4.5.1, but not in gcc-4.6.1. 


Also, if I do the same in a non-template function, it works fine, as expected.


[Bug c++/52688] New: static local variable can accessed from local class of function template

2012-03-23 Thread sir_nawaz959 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688

 Bug #: 52688
   Summary: static local variable can accessed from local class of
function template
Classification: Unclassified
   Product: gcc
   Version: 4.6.1
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: sir_nawaz...@yahoo.com


As per the C++ specification, static local variable can be accessed from local
class of function template, but GCC 4.6.1 gives error for the following
code-snippet:

templatetypename T
T f()
{
  static const double staticLocalVariable = 100.0;
  struct local
  {
  static double f() { return staticLocalVariable; }
  };
  return T(local::f());
}

int main() {
std::cout  fdouble()  std::endl;
}

While gcc-4.5.1 compiles fine this code, gcc-4.6.1 gives error, saying:

undefined reference to `staticLocalVariable'