23

My experience until now is, that the error discovery of Eclipse is horribly buggish without any solutions (Tried __GXX_EXPERIMENTAL_CXX0X__, -std=c++0x, -std=c++11 in nearby every point of the settings). I am at the point that I dont want to search for a solution no more. Now I just want to see solely real compiler errors. But how to accomplish this?

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103

5 Answers5

20

UPDATE: It's been a long time since I posted the original answer and it has become outdated. I double-checked today (Mar 15, 2014): in Eclipse Kepler (Build id 20130614-0229) it is sufficient to

  • add under Project > Properties > C/C++ Build > Settings then on the Tool Settings tab GCC C++ Compiler > Miscellaneous the -std=c++11 flag,

  • then under Window > Preferences > C/C++ > Build > Settings on the Discovery tab chose CDT GCC Built-in Compiler Settings and add the -std=c++11 flag to Command to get compiler specs. On my machine it looks like this after the change:

    ${COMMAND} -E -P -v -dD -std=c++11 "${INPUTS}"

  • clean and rebuild both your project and your index (Project > C/C++ Index > Rebuild) as Eclipse tends to cache error messages and show them even though they are gone after changing the settings.

This works on my machine for sure. If it doesn't on yours, then you might want to give a shot to this: C++11 full support on Eclipse although I am neither sure about the correctness of this approach nor was it necessary to do it on my machine. As of March 7, 2014 users claim that it helped them whereas the above approach didn't.


The original post from 2012, now outdated:

These bogus errors come from Codan. I also issued a bug report (C++03!!!) but the same problem shows up in the latest stable Eclipse so I don't think much has happened :(

Workaround:

Click on the project properties, then C/C++ General > Code Analysis > Syntax and Semantic Errors and deselect whatever false errors you are getting.

I just want to see solely real compiler errors

Of course, you can disable there the static analysis completely, in that case you can accomplish exactly what you want.


UPDATE: 2 users have reported that what Jeevaka wrote helped them. I have tried what he wrote, it did not help me with Juno SR1 and CDT 8.1.1. Perhaps Codan developers have improved static analysis in Juno SR2 and CDT 8.1.2

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • Just reinstalled eclipse, made a new project took a while but no improvement. I dont know why, but I cant work in a project full of errors even if they are false positives. This is the last chance to stop this error annoy me. Thanks. – ManuelSchneid3r Nov 19 '12 at 21:39
  • @DevNoob If you re-install Eclipse, you have to disable the static analysis again. I personally turned static analysis completely off, it makes tons of false positives. – Ali Nov 19 '12 at 22:24
  • @DevNoob I didn't understand your last comment. Did you manage to get rid of the false errors finally? – Ali Nov 20 '12 at 18:21
  • Yes I got rid off false positives, but unfortunately of the positive positives too. But its better to work now. – ManuelSchneid3r Nov 20 '12 at 18:26
  • 1
    @DevNoob Yes, that's what I did too, and yes, you don't get the true errors from Codan but only later from the compiler. The whole thing is because Codan and the compiler have different understanding of C++ (and Codan is buggy). I wonder whether there is any work with clang, in that case the same program would do the static analysis and the compilation, not to mention the better error messages. In any case, I am glad that you can actually work now! – Ali Nov 20 '12 at 18:39
  • The error is not _really_ bogus, the default indexer settings adhere to the c++97 standard, which can be changed, but I agree it's far from obvious. – Kristóf Szalay Mar 14 '14 at 14:26
  • @KristófSzalay In my case, it was bogus, it failed on a code that was strictly C++98 compilant according to gcc, clang and visual studio. That code is not shown in the answer; please read the bugreport I link in the answer. – Ali Mar 14 '14 at 14:35
  • @KristófSzalay Are you the downvoter? If yes, could you explain the reason why you downvoted the answer? – Ali Mar 14 '14 at 14:37
  • Yes, I was. The reason being that you proposed a workaround for a solvable problem; I tried your code samples in my CDT, and they worked correctly. It's true that CDT may have improved in the last two years, but at least now, just turning Codan (or a subset of it) off is not the right answer. – Kristóf Szalay Mar 14 '14 at 14:46
  • @KristófSzalay OK, I have updated my answer. Please reconsider your downvote. There is no need to downvote my other similar answers, I will update them today. – Ali Mar 14 '14 at 15:28
  • Oh, I didn't mean to do so, just stumbled upon this question after configuring a new Eclipse install. – Kristóf Szalay Mar 14 '14 at 15:35
  • @KristófSzalay Well, your downvote did give the push I needed to update my answer. :) – Ali Mar 14 '14 at 16:11
  • Works with Luna (20140925-1800) – kallaballa Oct 06 '14 at 10:16
  • adding -std=c++11 for all CDT projects, won't make gcc complain about C projects? – user1284631 Oct 17 '14 at 12:09
  • @axeoth Point taken. I am afraid that if you have both C and C++ projects, you *may* have to remove that flag manually if you work on a C project... That's painful. :( I haven't tested it though. Feel free to submit a bugreport to the Codan developers. ;) – Ali Oct 17 '14 at 15:02
  • @axeoth And is that less painful? :( I simply don't understand why the Codan developers don't make it easier; people are having so much pain with this... – Ali Oct 17 '14 at 15:54
  • I know. It is painful and it seems to be such a little feature. More, on project properties, in C/C++ Build settings, you can choose the dialect of the language. Sadly, it is for compilation only, not for indexer... I cannot understand their vision of the things. This bug alone thrown me for a while in the CodeBlocks world, but came back to Eclipse CDT. Still, you never know... – user1284631 Oct 17 '14 at 18:43
6

I was troubled by Cordian errors for c++11 code that compile perfectly in gcc with all warnings enabled as well. I found what I think is the root cause, at least it was in my case. Few other questions on Cordian errors for c++11 are closed as duplicates of this question and point to this question. So I though I would post my answer here.

This is what I found: Project Properties > C++ General > Preprocessor … > Entries > GNU C++ > CDT GCC Builtin Compiler Settings has *__cplusplus=199711L* as one of the entries.

I changed it as follows: In the Window > Preferences > C/C++ > Build > Settings > Discovery tab selected CDT GCC Builtin Compiler Settings and changed ${COMMAND} -E -P -v -dD ${INPUTS} to ${COMMAND} -E -P -v -std=c++11 -dD '${INPUTS}'. Then hit Apply. The errors were gone after next build.

I am using Juno SR2 with CDT 8.1.2 and handmade make files.

Adding a little more color:

I am no expert, but here is what I think happened in my case:

Cordian gather errors in multiple ways.

One is parsing the compiler output. -std=c++11 in my Makefile ensured that this part worked right all along as invoking the same Makefile through terminal didn't flag any errors.

Another is through 'Code Analysis'. For this, and probably for other tasks, Ecplise need to know the settings that compiler would use. Eclipse find these by invoking the command I edited above and parsing the output. By ticking the 'Allocate console in the Console View' before hitting 'Apply' it is possible to view the output of this command. These settings include include directories and defines such as __cplusplus. When these match what gcc would use when invoked through my Makefile the results are consistent.

When I was experimenting with the problem using #pragma message inside headers I thought __GXX_EXPERIMENTAL_CXX0X__ is what is wrong and saw some online suggestions for setting this manually, but that seemed to be a workaround as well.

Aelian
  • 665
  • 1
  • 8
  • 13
  • Weird. I am using Juno SR1 (CDT 8.1.1) an it has `__cplusplus=1`. I don't have anything on the Discovery tab you write but as I see you are just passing the `-std=c++11` flag to the compiler so it shouldn't matter. Strange, I don't see how it could resolve the issue. – Ali Mar 17 '13 at 18:59
  • Just had a peek at an older box with Eclipse Indigo / gcc 4.6.3 and sure enough __cplusplus was set to 1. [link](http://stackoverflow.com/questions/7530047/gnu-c-macro-cplusplus-standard-conform) explains why, gcc had a bug that was fixed in gcc 4.7. According to the c++11 standard it should be 201103L. – Aelian Mar 18 '13 at 02:38
  • In my case, your instructions were good, but I had to manually rebuild the indexer database: Project -> C/C++ Index -> Rebuild – Pedro Lamarão Aug 13 '13 at 21:05
  • @Ali The static analyzer decides on things such as if a certain symbol was or was not declared. Declarations may be conditional on macro definitions. For example: with GCC 4.7, if you include the symbol `std::uintptr_t` shall be defined if and only if `__GXX_EXPERIMENTAL_CXX0X__` is defined. – Pedro Lamarão Aug 13 '13 at 21:07
  • @PedroLamarão Yes, I know. And I would assume that the static analyzer has access to the exact same defines as the compiler if I set that within the IDE. If you look at the question, even in the question it is mentioned that the `__GXX_EXPERIMENTAL_CXX0X__` is defined. Anyway, I get a bunch of false errors with the newest Eclipse Kepler that aren't even C++11 related. In my opinion, they shouldn't ship an Eclipse that produces such large amount of bogus errors. Having said that, I still use Eclipse CDT. – Ali Aug 13 '13 at 21:20
  • @Ali I am using Eclipse Kepler and, with the proper adjustment in the workspace-wide Discovery options, all is fine building programs which reference C++11 declarations and Windows SDK declarations. – Pedro Lamarão Aug 13 '13 at 21:27
  • @PedroLamarão I am not that lucky :( Even Eclipse Kepler is having static analysis issues on plain C++98 code. Well, I will check that Discovery options again... – Ali Aug 13 '13 at 21:30
6

On a fresh Eclipse install, triggering one macro and rebuilding the index solved it:

Projects->Properties->Preprocessor Includes Select GNU C++ Select CDT User Setting entries Press Add

and add a preprocessor macro with name __cplusplus and value 201103L.

Finally, rebuild the index. (Project->C/C++ Index->Rebuild)

Kristóf Szalay
  • 1,177
  • 1
  • 8
  • 19
1

You can also remove problematic parts of code from the CDT scope by fllowing next steps:

  • Go to the Project Properties->C/C++ General->Preprocessor include path, Macros, etc
  • Select desired language on Entries tab
  • Add->Preprocessor macro
  • Enter name "MY_CODAN_MACRO" and value "1"
  • Now you can write:

    #idndef MY_CODAN_MACRO
    // this code is visible by compiler only
    #else
    // this code is visible by code analysis and CDT, but not visible by compiler
    #endif
    

    I think this trick is possible in Indigo+. I'm using Juno.

    Alex
    • 63
    • 1
    • 6
    -1

    I realize question was asked a long time ago but since the problem persists (I user Kepler and get the same errors) I will post another possible workaround.

    One can create separate source file and redefine functions he want to use there (in general namespace e.g.). After I created function like that

    std::string to_string(long long num) {
        return std::to_string(num);
    }
    

    and started to use to_string instead of std::to_string in main sources (I added the extra one with including) eclipse did not mark code as errors any more.

    Of course the errors are marked in the extra include but it does not contain logic so you don't even look there.

    Cthulhu
    • 1,379
    • 1
    • 13
    • 25