This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53875] New: calls to const functions are eliminated at -O0
- From: "James.H.McKim at nasa dot gov" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 06 Jul 2012 14:09:12 +0000
- Subject: [Bug c++/53875] New: calls to const functions are eliminated at -O0
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53875
Bug #: 53875
Summary: calls to const functions are eliminated at -O0
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: James.H.McKim@nasa.gov
Compiler version 4.6.3.
System: ubuntu 12.1
When source containing a call to a const function is compiled, that function's
invocation is always (regardless of -O level) eliminated if the returned result
is discarded. That action is an optimization, and when no optimization is
specified, having it happen is surprising.
If the compiler is intended to always eliminate, it would be helpful if there
was a diagnostic indicating the elimination. For instance, instead of the
warning "statement has no effect", maybe "statement has no effect,
eliminating".
The code was compiled with the command:
g++ -O0 -S -o t1b.lst t1b.cxx
The example code (t1b.cxx):
extern int pthread_self (void) __attribute__ ((__const__));
int main() {
// Demonstrate the compiler doesn't emit this call.
pthread_self();
// A workaround.
// volatile int x = pthread_self();
return 0;
}