https://bugs.llvm.org/show_bug.cgi?id=38657
Dimitry Andric <dimi...@andric.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dimi...@andric.com
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Dimitry Andric <dimi...@andric.com> ---
As far as I can see, the code is invalid. The String() temporary object created
in the first line of main() is immediately destructed afterwards, making str1
point to invalidated memory.
Demonstration:
/* test.cpp */
#include <string.h>
#include <assert.h>
#include <stdio.h>
struct String {
char content[100];
String (const char* a) {
strcpy(content, a);
}
~String () {
printf("destroying String\n");
}
operator const char* () const {
return content;
}
};
int main()
{
char const* str1 = String("three");
printf("checking assertion\n");
assert(strcmp(str1, "three") == 0);
return 0;
}
$ clang -O2 pr38657-2.cpp -o pr38657-2
$ ./pr38657-2
destroying String
checking assertion
Assertion failed: (strcmp(str1, "three") == 0), function main, file
pr38657-2.cpp, line 23.
Abort trap (core dumped)
E.g., you should ensure the String object is not destroyed before checking the
assertion.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs