Why does CLion not allow me to have nested ternary operators?

281 views Asked by At

I am trying to have nested ternary expressions in C++14. My code is the following:

#include <bits/stdc++.h>

using namespace std;

int main() {
    int i = 5;
    string result = i % 2 == 0 ? "a" : i % 3 == 0 ? "b" : "c";

    return 0;
}

I am using CLion. I get an error on the last nexted expression i % 3 == 0 ? "b" : "c" saying Type 'const char[2]' and 'const char[2]' are not compatible. What am I doing wrong?

If it helps, here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.6)
project(TestCLion)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES relop.cpp)
add_executable(TestCLion ${SOURCE_FILES})
1

There are 1 answers

0
npas On BEST ANSWER

This is a known bug in CLion.

The code will compile without errors. (using CLion 2017.3.1, GCC 6.3.0)