Consider this piece of code
class Example
{
};
class ExampleAccessor
{
public:
struct ConstructionFlag
{
ConstructionFlag()
{
}
~ConstructionFlag()
{
}
};
explicit ExampleAccessor(Example&)
{
}
ExampleAccessor(Example&, const ConstructionFlag&)
{
}
};
int main()
{
ExampleAccessor accessor(ExampleAccessor::ConstructionFlag());
}
Which is the minimal example of something I found in our code tree today. This compiles without any errors or warnings (on my compilers gcc 4.4 on Linux and mingw 4.5.2 on Windows both C++98). Reading the code I find this to be odd because I would have expected to get a compiler error for a mismatch parameter type while trying constructing an ExampleAccessor object.
It turns out that the compiler actually treats line 30 as a function declaration and produces no code for it.
Anyone else come across this before?
Can we get the compiler to warn/error about this (I tried most of the warning switches I was aware of without effect)
Is there a solution?
Actually I think they answer to the lastq question might be yes use a static const object rather than a temporary.