go-qml / qml

QML support for the Go language
Other
1.96k stars 187 forks source link

Build error after commit e033ffcc21 #11

Closed eivindro closed 10 years ago

eivindro commented 10 years ago

I get this build error on windows/mingw compiler after commit e033ffcc21

In file included from .\all.cpp:2:0:
.\cpp/capi.cpp: In function 'void windowShow(QQuickWindow_*)':
.\cpp/capi.cpp:178:22: error: expected type-specifier before 'ShowWindow'
     reinterpret_cast<ShowWindow *>(win)->show();
                      ^
.\cpp/capi.cpp:178:22: error: expected '>' before 'ShowWindow'
.\cpp/capi.cpp:178:22: error: expected '(' before 'ShowWindow'
.\cpp/capi.cpp:178:34: error: expected primary-expression before '>' token
     reinterpret_cast<ShowWindow *>(win)->show();
                                  ^
.\cpp/capi.cpp:178:40: error: 'QQuickWindow_* {aka void*}' is not a pointer-to-object type
     reinterpret_cast<ShowWindow *>(win)->show();
                                        ^
.\cpp/capi.cpp:178:48: error: expected ')' before ';' token
     reinterpret_cast<ShowWindow *>(win)->show();
                                                ^
niemeyer commented 10 years ago

Please see if the latest push to tip helps.

radisson commented 10 years ago

Trying to get it working on Windows. Same results than original poster with the latest push.

niemeyer commented 10 years ago

Is that the full error or is there any other warning before that?

eivindro commented 10 years ago

Got it!

Turns out one has to write class in front of ShowWindow, like so:

    reinterpret_cast<class ShowWindow *>(win)->show();

This is probably because there is a global function called ShowWindow defined in the Win32 API which naturally is available when using mingw, I have to admit that ShowWindow is an extraordinary bad name for a class (it sounds like a function), it just shows that you have to be careful when naming variables in C/C++ even when they're internal.

niemeyer commented 10 years ago

To me it shows that C++ is extraordinarily bad at namespacing and error reporting.

Thanks for figuring it out.

oblitum commented 10 years ago

Maybe a case for blaming the compiler instead. In the past, building Qt with clang I got trivial errors that go unnoticed with g++ (let's not even talk about msvc). I got better error messages and it even provided fix suggestions...

oblitum commented 10 years ago

just to compare

code

void x(){}
struct x{};

int main()
{
    reinterpret_cast<x *>(0);
}

clang 3.4

francisco@Ubuntu:~/Projetos/samples$ clang++ sample.cpp
sample.cpp:6:22: error: must use 'struct' tag to refer to type 'x' in this scope
    reinterpret_cast<x *>(0);
                     ^
                     struct 
sample.cpp:1:6: note: struct 'x' is hidden by a non-type declaration of 'x' here
void x(){}
     ^
sample.cpp:6:5: warning: expression result unused [-Wunused-value]
    reinterpret_cast<x *>(0);
    ^~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.

gcc 4.8

francisco@Ubuntu:~/Projetos/samples$ g++ sample.cpp 
sample.cpp: In function ‘int main()’:
sample.cpp:6:22: error: expected type-specifier before ‘x’
     reinterpret_cast<x *>(0);
                      ^
sample.cpp:6:22: error: expected ‘>’ before ‘x’
sample.cpp:6:22: error: expected ‘(’ before ‘x’
sample.cpp:6:25: error: expected primary-expression before ‘>’ token
     reinterpret_cast<x *>(0);
                         ^
sample.cpp:6:29: error: expected ‘)’ before ‘;’ token
     reinterpret_cast<x *>(0);
                             ^