[Bug c/30583] New: Non-static inline functions cause bugs when defined more than once in different files

2007-01-24 Thread Ivan dot Scherbakov at acronis dot com
When compiling with optimization turned off (-O0), inline functions are no
actually compiled as inline, but
when multiple source files contain inline functions of the same name, every
call to such function from any file
will actually transfer control to the function defined in the file first
specified in linker list. No errors
or warnings are actually being generated leading to hard-to-detect problems
while compiling big projects.

Example:
1.cpp
#include 
inline void test(){ printf("1"); }
void test1(){ test(); }
2.cpp
#include 
inline void test(){ printf("2"); }
void test2(){ test(); }
m.cpp
void test1();void test2();
int main(){test1(); test2(); return 0;}
-
When optimizations are turned on (-O2), the program outputs "12" as it should).
If you turn optimization to 0, (g++ -O0 1.cpp 2.cpp m.cpp), the program outputs
"11".


-- 
   Summary: Non-static inline functions cause bugs when defined more
than once in different files
   Product: gcc
   Version: 4.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
    ReportedBy: Ivan dot Scherbakov at acronis dot com


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



[Bug c++/30583] [ODR] Non-static inline functions cause bugs when defined more than once in different files

2007-02-11 Thread Ivan dot Scherbakov at acronis dot com


--- Comment #3 from Ivan dot Scherbakov at acronis dot com  2007-02-12 
06:03 ---
The way of declaring inline functions as static is evident, but in fact, when
building large projects containing several libraries the case when the same
inline function is defined more than once in different libraries and those
libraries fail in a very strange way when linked together is *very hard* to
diagnose.
The proposal was to include a warning/error message when the ODR rule is
violated, as when multiple definitions of an ordinary function are encountered.


-- 

Ivan dot Scherbakov at acronis dot com changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |


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