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: unassig...@gcc.gnu.org
        ReportedBy: james.h.mc...@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;
}

Reply via email to