eclipse-paho / paho.mqtt.cpp

Other
1.03k stars 438 forks source link

mqtt\ssl_options.h(470): error C2062: type 'auto' unexpected #513

Open ffreality opened 2 months ago

ffreality commented 2 months ago

I built both paho.mqtt c and cpp libraries without problem and integrated them to Unreal Engine 5. But when I try to open UE5 project, Visual Studio 2022 gives this error.

mqtt\ssl_options.h(470): error C2062: type 'auto' unexpected

auto verify(bool on=true) -> self& {
    opts_.set_verify(on);
    return *this;
}

I am using openssl 1.1.1t and added it to UE5, too.

fpagliughi commented 2 months ago

Seems like a problem with the Visual Studio language server. Is there a way so set what version of C++ is expects? C++11, C++17, etc?

ffreality commented 2 months ago

Seems like a problem with the Visual Studio language server. Is there a way so set what version of C++ is expects? C++11, C++17, etc?

Unreal Engine 5.4.4 specifically use C++ 20

fpagliughi commented 2 months ago

Sorry, I'm not much of a Windows developer anymore.

The trailing return type is valid C++11 (and beyond) syntax. The library builds fine on the command line when I use CMake and the MSVC CLI tools.

Is it maybe that it's trying to build the library for C++20, and something about that has changed? I've only been testing with C++11, and now C++17 for the upcoming version.

ffreality commented 2 months ago

Sorry, I'm not much of a Windows developer anymore.

The trailing return type is valid C++11 (and beyond) syntax. The library builds fine on the command line when I use CMake and the MSVC CLI tools.

Is it maybe that it's trying to build the library for C++20, and something about that has changed? I've only been testing with C++11, and now C++17 for the upcoming version.

yes, probably you are right. I will make a for and try to fix it. Maybe we can publish it as a different branch. Btw. C library doesn't have this problem.

fpagliughi commented 2 months ago

Yeah, the C compiler isn't putting out breaking changes every 3 years!

Are you compiling with the CMake build, or using your own? (Meaning the CMake should be forcing the compiler to use C++11.. and why don't I see the problem building from the command line).

Also, what version of the library are you using? The latest v1.4.1 release?

ffreality commented 2 months ago

Yeah, the C compiler isn't putting out breaking changes every 3 years!

Are you compiling with the CMake build, or using your own? (Meaning the CMake should be forcing the compiler to use C++11.. and why don't I see the problem building from the command line).

Also, what version of the library are you using? The latest v1.4.1 release?

I am using CMake and master version. I don't get any error while building library's itself and I can get mqtt static lib in my install location. Like you said, generated solution uses older version of C++

But after integrating it to Unreal Engine 5 (it uses C++ 20), project give that error and doesn't open.

This is my plugin's third party folder. https://github.com/FF-Plugins-Active/FF_MQTT/tree/main/Source/FF_MQTT/ThirdParty/paho_cpp/Win64

fpagliughi commented 2 months ago

Sorry I have no experience with Unreal Engine and have no idea what it may be trying to do.

Out of curiosity, I tried compiling as C++20, by updating the main CMake file:

-set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD 20)

It compiled fine, but I only tried it on Linux with g++, since I don't have a Windows machine readily available at the moment. I just wanted to rule out a problem with standard C++ as the standard evolves.

The really crazy thing about the error is that it's not even the first place in that file where it encounters auto as a function return type. https://github.com/eclipse/paho.mqtt.cpp/blob/3631bce7e0bd74cc11a46410669ccd2e23b6caed/include/mqtt/ssl_options.h#L461-L473

It's in the middle of the builder class where nearly every method uses that same pattern.