1

I have some code which CLion will fail to parse. For example, it might be included into another file, but must rely on code it does not itself include.

Now, in an answer to this question, we learn that CLion's parser recognizes the define __CLION_IDE__, so that you can write blocks such as:

#ifdef __CLION_IDE__

typedef int type_we_assume_is_define;
#endif

... which should only be parsed by CLion. But - I can't have even that in my file, for reasons. Is there a way to force CLion's parser to recognize some more type definitions, or at least preprocessor macros - not via the source file itself?

I'm using CLion 2021.3.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • With gcc, you can use the [`-include file`](https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#index-include) command-line option in order to include a file without adding an `#include` directive. You'd have to put the alternative typedefs in some file and tell CLion to apply that command line option when compiling the relevant source file. – rici Dec 26 '21 at 18:17
  • This is an excellent question. I have code that uses `__CUDACC__` directives to make some uniform cross-platform API that I use throughout my code bases. The code gets compiled by both vanilla gcc and nvcc when I build, so it's useful for me to see if all is well regardless of whether `__CUDACC__` is defined, so, at the very least, I wanna be able to toggle. Linking here from CLion issue tracker. – Greg Kramida Dec 06 '22 at 20:11
  • 1
    Submitted as CLion issue: https://youtrack.jetbrains.com/issue/CPP-31406/Need-global-and-file-scope-C-preprocessor-defines-for-CLion-parser-clang-d-arguments – Greg Kramida Dec 06 '22 at 20:26

0 Answers0