2

I just came across a weird problem that happens ONLY on MSVC with Clion but not on other compilers(I tried gcc on Linux and Visual Studio both no such problem, with the same code).

With these codes:

#include <vector>
#include <algorithm>
using namespace std;
int main() {
    vector<int>v = {1,2,3,4,5};
    make_heap(v.begin(), v.end());
    v.push_back(6);
    push_heap(v.begin(), v.end());
}

an error "In instantiation of function template specialization 'std::push_heapstd::_Vector_iterator<std::_Vector_val<std::_Simple_types<int > > >' no type named 'value_type' in 'std::indirectly_readable_traitsstd::_Vector_iterator<std::_Vector_val<std::_Simple_types<int > > >'" will then be shown

enter image description here

is it a bug of Clion or MSVC?

P.S. I can still build and run it so it might not be a compiler error; (Making me even more confused)

  • 2
    Is this an actual compiler error? Or is this simply a bug in Intellisense or whatever technology is being used? – PaulMcKenzie Jul 18 '20 at 03:48
  • @PaulMcKenzie Clion using MS' intellisense for its backend inline parsing? Interesting; I didn't know that. – WhozCraig Jul 18 '20 at 04:09
  • @PaulMcKenzie I can still build and run it so it might not be a compiler error though it seems to be – bright yang Jul 18 '20 at 05:05
  • 1
    Of course you can still build it, because it is not a compiler error. The error is in a third-party tool, not the compiler. You need to distinguish between what are actual compiler errors, and what are third-party tool errors. The question suggests it is a compiler error, when it certainly isn't (since you were able to build the program). – PaulMcKenzie Jul 18 '20 at 05:30

1 Answers1

-2

It looks like you cannot intialize vector with the following command:

vector<int>v = {1,2,3,4,5}; 

Change it to:

vector<int> vect{ 1, 2, 3, 4, 5 };

Compile and run the code and see if it still has problems.

EDIT: Some people are saying it is unlikely however look at the link: What is the easiest way to initialize a std::vector with hardcoded elements?

If you scroll down to the second answer it says:

If your compiler supports C++11, you can simply do:
std::vector<int> v = {1, 2, 3, 4};

As you did not tell us your compiler version and environment it is very hard to determine if this is the problem. Also note that:

This is available in GCC as of version 4.4. 
Unfortunately, VC++ 2010 seems to be lagging behind in this respect.

So if you are using an older version of VC++ then you are out of luck...

Yunfei Chen
  • 630
  • 1
  • 8
  • 20
  • that seems very unlikely – Mooing Duck Jul 18 '20 at 03:27
  • 1
    @YunfeiChen You should first consider whether the error is an actual compiler error, and not an error with the IDE's code parser. A programmer should never change code to match what a buggy IDE is suggesting. – PaulMcKenzie Jul 18 '20 at 03:47
  • @PaulMcKenzie I did it does not work on my VSC either, so it looks like: std::vector v = {1, 2, 3, 4}; is not the correct syntax. – Yunfei Chen Jul 18 '20 at 03:50
  • 1
    No, what I mean is whether the error is an actual compiler error. MSVC compiler errors are named `Cxxx`. If it is an Intellisense error, that is not a compiler error, but a bug in the Intellisense. – PaulMcKenzie Jul 18 '20 at 03:52
  • 1
    Intellisense is the technology that is used in the Visual Studio IDE that looks up classes, types, etc. and underlines or identifies missing types, etc. However it is *not* the compiler. If you look at the question, nowhere is it mentioned that the error is an actual compiler error. Visual Studio compiler errors start with `C` and are numbered. That's why giving the advice to change code so that it makes an IDE tool happy is the wrong (bad) advice. – PaulMcKenzie Jul 18 '20 at 04:00
  • @PaulMcKenzie As you think it is a Interllisense error, did you notice Visual Studio does not have such problem and only CLion does? as I mentioned in the questonn – bright yang Jul 18 '20 at 05:12
  • @brightyang Whatever the tool is, it doesn't matter. What matters is that the error is *not* a compiler error. Whether it is Intellisense, CLion, or some other code parsing tool, the error is not a compiler error. The bottom line is you don't change your code because a third-party tool has bugs. – PaulMcKenzie Jul 18 '20 at 05:32