[Bug c/49653] New: Undefined reference to inlined function with -O0,-std=c99

gary at intrepid dot com gcc-bugzilla@gcc.gnu.org
Tue Jul 5 22:13:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49653

           Summary: Undefined reference to inlined function with
                    -O0,-std=c99
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gary@intrepid.com


Given,

$ cat -n inline_trouble.c
     1  inline long trouble(long a, long b)
     2  {
     3      return a + b;
     4  }
     5
     6  long two = 2;
     7
     8  int main()
     9  {
    10      long result = trouble(two, two);
    11      return (int)result;
    12  }

$ gcc --version
gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)

This test compiles and links cleanly at -O2,-std=c99:

$ gcc  -std=c99 -O2 inline_trouble.c

At -O0 -std=c99, it fails to link.

$ gcc  -std=c99 -O0 inline_trouble.c
/tmp/ccXya7LE.o: In function `main':
inline_trouble.c:(.text+0x1d): undefined reference to `trouble'
collect2: ld returned 1 exit status

Note that gnu90 doesn't have this issue.

$ gcc  -std=gnu90 -O0 inline_trouble.c

(Although GCC 4.5.1 is used in the test above, it is likely that this problem
can be reproduced with GCC built from the trunk.)



More information about the Gcc-bugs mailing list