cLion not printing error when crashing

Answered
 

I have a weird issue that I just learned about. If I run this code in Visual Studio I get output that is NULL/error. But when I run in cLion I just get app crash and no feedback.

VS error :

Exception thrown: read access violation.
this was nullptr.

Here is my config:

main.cpp

#include <iostream>

using namespace std;

class testNothing {
public:
    testNothing *test;
    void donothing() { cout << test << endl; };
};

int main()
{
    testNothing *hey = nullptr;

    hey->donothing();

    return 1;
};

CMakeList.txt

cmake_minimum_required(VERSION 3.8)
project(tests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
0
1 comment

Null-pointer dereference is an Undefined Behaviour in C++, so different compilers might do different things with it. In your case Visual Studio and GCC are behaving differently, which is expected. Also note that CLion uses an existing compiler (e.g. GCC) instead of bundling a proprietary one (like Visual Studio), so this behaviour is unfortunately out of our control.

0

Please sign in to leave a comment.