c++98/c++03 constructor overloading
Hi,
With gcc-4.2 and earlier, and with subsequent versions of gcc when
using the -std=c++98 option, the following code fails to compile:
--------------------------
#include <iostream>
#include <ostream>
enum ByRef {by_ref};
template <class T>
class MyClass {
T t;
public:
MyClass(const T& arg): t(arg) { // (1)
std::cout << "Without ByRef tag" << std::endl;
}
MyClass(T arg, ByRef): t(arg) { // (2)
std::cout << "With ByRef tag" << std::endl;
}
};
int main() {
int i = 0;
MyClass<int&> m2(i, by_ref);
}
--------------------------
gcc ignores the ByRef tag, and picks constructor 1, and then fails to
compile because of the resulting reference to a reference.
Without the -std=c++98 option, gcc-4.3 onwards pick the right overload
(constructor 2), as does Comeau in strict c++03 mode.
Is this a gcc bug or do c++98 overload rules compel the tag
enumeration to be ignored and the incorrect constructor to be called?
If c++98 overload rules compel this behaviour, at what point did it
change (is it a c++03 thing, or in anticipation of c++0x?)
Chris