[Bug c++/81260] New: Error "taking address of temporary" is missing

2017-06-30 Thread carljohnson95 at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81260

Bug ID: 81260
   Summary: Error "taking address of temporary" is missing
   Product: gcc
   Version: 5.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: carljohnson95 at gmx dot com
  Target Milestone: ---

Command line:
>c++ main.cpp -std=c++14 -Wall -Wextra -Wpedantic -fno-strict-aliasing -fwrapv 
>-o 1.exe
Compiler output:

main.cpp: In function 'int main()':
main.cpp:10:22: error: taking address of temporary [-fpermissive]
   cout << (int)&((A)1) << endl; //  error: taking address of temporary

This is the code:

// BEGIN
#include 
using namespace std;

class A{public:
  A(int a){this->a = a;}
  int a;
};

int main(void){
  cout << (int)&((A)1) << endl; //  error: taking address of temporary
  cout << (int)&((A)1 = 1) << endl; // No error
}
// END

According to the specs, shouldn't the second throw an error too? (assuming that
sizeof(A*)==sizeof(int))

[Bug c/81235] New: Realloc returns NULL while ti should not

2017-06-27 Thread carljohnson95 at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81235

Bug ID: 81235
   Summary: Realloc returns NULL while ti should not
   Product: gcc
   Version: 5.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: carljohnson95 at gmx dot com
  Target Milestone: ---

Created attachment 41638
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41638=edit
This attachment contains source file which causes the issue and log file which
contains alloc/realloc data.

system type: Windows 8.1
complete command line:
>gcc 1.c -Wall -Wextra -std=c99 -Wmissing-prototypes -Wstrict-prototypes 
>-Wold-style-definition -fno-strict-aliasing -fwrapv -o 1.exe
the compiler output: /

The source file which causes the issue is named "1.c" (in attachment). I am not
allowed to share whole code, so I renamed every single identifier and removed
extra space. It may be hard to read, but I don't have other way to share it.

The script is compiled correctly (I mean it doesn't throw any errors or
warnings). However, when executed, the process crashes. I spent a lot of time
trying to figure out what is actually causing the crash.

After debugging, I noticed that the crash is because function `realloc`
returned NULL. As I know, there might be two situations when `realloc` returns
NULL:
1. When a pointer is passed which didn't came from `alloc` or `calloc`
2. When there is no enough free space

The second possibility is not the case, because I ensured that there is enough
space. Also, I debugged it and noticed that `realloc` returns NULL when
requested size is 36 bytes.

So, the only left possibility is that I mistakenly passed bad pointer to
`realloc`. So, I wrote a function for debugging to inspect what pointers are
allocated/reallocated (you can see it in file "2.c" from attachment). I
analyzed the output log file and I didn't notice anything suspicious. Every
single time I call `realloc` I pass correct pointer. But, for some weird reason
when `36` bytes are reached, the NULL is received.

I have a lot of experience with mistakes with memory management, so I know how
to deal with that. However, this is not the case. I strongly believe this is a
bug with GCC. It usually takes me a few minutes to figure out where I made a
mistake, but this code took me a week and I still think I did everything right
and GCC messed something up.

The last thing I did is to compile it using VisualStudio. As I though, the
program works correctly and doesn't throw any error, wanrning or segfault.
In the file "log.txt" from the attachment you can see every single call of
alloc/realloc functions and its parameters and output. Maybe it helps.

Also, the crash doesn't happen every time. Approximatelly 50% of times I run
the same program it crashes.