CLion seems to not recognize operator overloading

Hello,

I have a problem with CLion's C++ code inspection.

There is my main function :

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string s1 ("Hello World!");
  string
s2 ("Test");
  string
s3 = s1 + s2;

  if (s1 == s2)
    cout << "No !" << endl;
  
cout << s3 << endl;
}


CLion underlines the section "s1 + s2" in red and says "binary operator '+' can't be applied to the expression of type 'string' and 'string'", and the section "s1 == s2", saying "Can't compare structures", but the code is compiling.

There is my CMakeLists.txt :

cmake_minimum_required(VERSION 3.3)
project(Test2)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")

set(SOURCE_FILES main.cpp)
add_executable(Test2 ${SOURCE_FILES})


When I turn on c++11, the error on "s1 == s2" disapear, but not the error on "s1 + s2".

I am using CLion 1.2.4 build #CL-143.1186

Thank you.

6 comments
Comment actions Permalink

Hi Hugo.

This example correctly works in my environment. Could you please attach a screenshot with Toolchains tab (Settings (Preferences) | Build, Execution, Deployment | Toolchains)?

0
Comment actions Permalink

Thanks for your response.

There is the toolchains window

0
Comment actions Permalink

i have the same problem. When i compile everything works fine.

In the previous version of clion i hadn't this problem.

0
Comment actions Permalink

Hi!

Thanks, we have found the problem. Please upvote the issue in our tracker: https://youtrack.jetbrains.com/issue/CPP-4681.

0
Comment actions Permalink

I have similar issue, CLion doesn't recognize overloading of operator = for std::pair:

 

 

 

0
Comment actions Permalink

@Vasyl, here is the related issue: https://youtrack.jetbrains.com/issue/CPP-8766. Feel free to comment or upvote, follow it to get updates.

0

Please sign in to leave a comment.