Disable Eclipse's error discovery. (Codan false positives)

后端 未结 5 919
遥遥无期
遥遥无期 2020-11-29 09: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

5条回答
  •  -上瘾入骨i
    2020-11-29 09:38

    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.

提交回复
热议问题