free-audio / clap-plugins

MIT License
61 stars 9 forks source link

Fix for compile error for MSVC due to GCC extension. #20

Closed COx2 closed 1 year ago

COx2 commented 1 year ago

I found source code that does not compile with MSVC. Please check the change difference.

This issue is due to the following circumstances.

Conditionals with Omitted Operands syntax label ?: "" is a GNU extension. It's not supported in MSVC (even in the latest version). Reference: https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html

The following source code can be used to verify that the compiler behaves differently.

// Type your code here, or load an example.
#include <iostream>
#include <cstdlib>

int main()
{
    const char* buffer = "This is a text.";
#if 1
    const std::string text = buffer ?: std::string("");
#else
    const std::string text = buffer ? std::string(buffer) : std::string("");
#endif
    std::cout << text << std::endl;
}

Demo by godbolt: compile by clang with -Wpedantic compile option. Compiler outputs warning message. Link: https://godbolt.org/z/zqv8YqzT4

Demo by godbolt: cmpile by msvc. Compile is failure. Link: https://godbolt.org/z/MGEbWh8a3

abique commented 1 year ago

Thanks, indeed this is a gcc/clang c/c++ extension to the language, I shouldn't have used it.