cppit / jucipp

A lightweight & cross-platform IDE supporting the most recent C++ standards. This project has moved to https://gitlab.com/cppit/jucipp.
https://gitlab.com/cppit/jucipp
MIT License
883 stars 98 forks source link

Discrepancies between gcc compiler and clang parser #286

Closed insunaa closed 8 years ago

insunaa commented 8 years ago

The default compiler in juCi++ is gcc/g++ (for some reason), while the parser uses clang. Clang and GCC have different levels of standards compliance which can very rarely lead to problems, for example this:

#include <iostream>

int main() {
  std::string 〄 = "Hello, World!";
  std::cout << 〄 << std::endl;
}

Is completely valid in clang, it compiles, outputting Hello, World!

gcc on the other hand does not compile and throws these errors:

Compiling and running /home//prog/emoji_variables/build/emoji_variables [ 50%] Building CXX object CMakeFiles/emoji_variables.dir/main.cpp.o /home//prog/emoji_variables/main.cpp:4:15: error: stray ‘\343’ in program std::string 〄 = "Hello, World!";                  ^ /home//prog/emoji_variables/main.cpp:4:16: error: stray ‘\200’ in program std::string 〄 = "Hello, World!";                    ^ /home//prog/emoji_variables/main.cpp:4:17: error: stray ‘\204’ in program std::string 〄 = "Hello, World!";                      ^ /home//prog/emoji_variables/main.cpp:5:16: error: stray ‘\343’ in program std::cout << 〄 << std::endl;                     ^ /home//prog/emoji_variables/main.cpp:5:17: error: stray ‘\200’ in program std::cout << 〄 << std::endl;                       ^ /home//prog/emoji_variables/main.cpp:5:18: error: stray ‘\204’ in program std::cout << 〄 << std::endl;                         ^ /home//prog/emoji_variables/main.cpp: In function ‘int main()’: /home//prog/emoji_variables/main.cpp:4:19: error: expected unqualified-id before ‘=’ token std::string 〄 = "Hello, World!";                  ^ /home//prog/emoji_variables/main.cpp:5:20: error: expected primary-expression before ‘<<’ token std::cout << 〄 << std::endl;                          ^~ make[2]: [CMakeFiles/emoji_variables.dir/build.make:63: CMakeFiles/emoji_variables.dir/main.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:68: CMakeFiles/emoji_variables.dir/all] Error 2 make: *** [Makefile:84: all] Error 2

The problem here is that the code looks completely valid in the IDE, there are no error markers, etc.

Proposed fix: Give the user an option to set the preferred compiler from within the IDE and then generate this in the CMakeLists.txt

SET(CMAKE_CXX_COMPILER g++) or SET(CMAKE_CXX_COMPILER clang++) for example, depending on the user settings.

eidheim commented 8 years ago

This is as it should be as prepackaged libraries on Linux are mostly compiled with g++, so the default compiler is used to avoid ABI incompatibilities. Additionally, parsing with libclang and compiling with g++ gives the warning and error capabilities of two compilers.

One can change the default compiler in preferences (cmake_command) if one wishes, and one can even create the build directories manually in case a project should have some specific cmake options added.

insunaa commented 8 years ago

Alright then, I'll close the issue. :)