[Bug c++/45594] New: g++ incorrectly treats inline function redefinition

justchecking8964 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 8 08:59:00 GMT 2010


If two separate .cpp files contain two versions of inline function with the
same signature, that are used by functions in the corresponding files, one of
them is dropped and all functions use only one of them.

Consider example:

main.cpp
-----------------------------
#include "test1.h"
#include "test2.h"

int main()
{
        print_out_1();
        print_out_2();
        return 0;
}
-----------------------------

test1.h
-----------------------------
#ifndef TEST1_H
#define TEST1_H

void print_out_1();

#endif // TEST1_H
-----------------------------

test2.h
-----------------------------
#ifndef TEST2_H
#define TEST2_H

void print_out_2();

#endif // TEST2_H
-----------------------------

test1.cpp
-----------------------------
#include "test1.h"
#include <stdio.h>

inline int print_stuff(int n)
{
        printf("number 255\n");
        return n;
}

void print_out_1()
{
        print_stuff(10);
}
-----------------------------

test2.cpp
-----------------------------
#include "test2.h"
#include <stdio.h>

inline int print_stuff(int n)
{
        printf("letter A\n");
        return n;
}

void print_out_2()
{
        print_stuff(10);
}
-----------------------------

The main() function simply calls print_out_1() function from test1.h and
print_out_2() function from test2.h, which in turn call print_stuff() inline
functions.

The expected output would be:
-----------------------------
number 255
letter A
-----------------------------

The actual output is:
-----------------------------
number 255
number 255
-----------------------------

This error appears for both debug and release (-O2) builds.


-- 
           Summary: g++ incorrectly treats inline function redefinition
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: justchecking8964 at gmail dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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



More information about the Gcc-bugs mailing list