I found an inconsistent behavior of the Q_INIT_RESOURCE()
macros in Qt, where it may fail if being compiled with GCC.
Consider the code:
do {
extern void func();
func();
}
while(false);
Here we declare an external function and call it: so far so good. That is the approach that the macros is using under the hood. Now let's try to call this code from two different functions, one in a namespace, the other in the global namespace:
void funcGlobal() {
do {
extern void func();
func();
}
while(false);
}
namespace ns {
void funcNamespace() {
do {
extern void func();
func();
}
while(false);
}
}
void func() { std::cout << 1; }
namespace ns {
void func() { std::cout << 2; }
}
As I can see, MSVC calls the ::func()
in both cases, but GCC calls ::func()
from the global function and ns::func()
from the functionNamespace
. Intuitively I find MSVC more consistent, but my question is: what does the standard say, and which compiler is correct?
Regarding the macros: due to the problem above calling the macros Q_INIT_RESOURCE()
from any function that is not in the global namespace causes the compiler error. I have to fix that using an additional level of indirection, wrapping the usage of the macros into a global function.