Let's assume we have one .cc file which contains the following:[surprising behavior snipped]
// ----------- file 1 -----------
#include <iostream>
template<typename T>
void foo(T t) { bar(t); }
void bar(int i) { std::cout << "int: " << i << std::endl; }
void anotherFunc();
int main() { foo(5); anotherFunc(); }
// ------------------------------
And another file which contains the following:
// ----------- file 2 -----------
#include <iostream>
template<typename T>
void foo(T t) { bar(t); }
void bar(long i) { std::cout << "long: " << i << std::endl; }
void anotherFunc() { foo(7); }
// ------------------------------
So my question is: Is this behavior (ie. the inconsistent behavior ofI think your code violates the One-Definition-Rule. The template function
these template functions depending on whether they are inlined or not)
standard-conforming, is it Undefined Behavior(TM), or is it a bug in gcc?
foo() is defined in two significantly different ways in the two files. As
far as I know, no diagnostic is required for such errors.
[snip]
Best
Kai-Uwe Bux