This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/79349] unused std::string is not optimized away in presense of a call
- From: "hiraditya at msn dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 02 May 2017 20:10:09 +0000
- Subject: [Bug libstdc++/79349] unused std::string is not optimized away in presense of a call
- Auto-submitted: auto-generated
- References: <bug-79349-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79349
AK <hiraditya at msn dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |NEW
Resolution|WORKSFORME |---
--- Comment #3 from AK <hiraditya at msn dot com> ---
(In reply to AK from comment #2)
> The problem is exceptions. When I compile without exceptions
> (-fno-exceptions) g++ does optimize this away and gives same output as
> clang. It seems clang++ compiles without exceptions by default and behaves
> like g++ when -fexceptions is passed.
Correction:
For the example:
#include<string>
int main() {
std::string s("abc");
return 0;
}
clang (with libc++) optimizes away the std::string even in the presence of
exceptions (-fexceptions). When I compile without exceptions (-fno-exceptions)
g++ does optimize the std::string away.
However, when I introduce a call:
#include<string>
void foo();
int main() {
std::string s("abc");
foo();
return 0;
}
clang++ still optimizes the std::string but g++ does not. I think the problem
is with libstdc++ because when clang is using libstdc++ I can see the
destructor.
Sorry for the confusion.