Skip to content

Instantly share code, notes, and snippets.

@jonahgraham
Created March 22, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonahgraham/db691d9b36d5fd4e68bee58df1aed897 to your computer and use it in GitHub Desktop.
Save jonahgraham/db691d9b36d5fd4e68bee58df1aed897 to your computer and use it in GitHub Desktop.
CDT: Completions suggesting unreachable code (originally http://stackoverflow.com/a/42956434/2796832)

CDT does not present unreachable in code completions. The issue you are facing is the definition of unreachable AFAICT.

In C, everything that is not static is "public" and can be called from anywhere else. No declaration is even necessary (although I would recommend -Wall -Werror, but that is a separate discussion).

For example, consider file.c with contents:

static void func_private1(void) {}
static void func_private2(void) {}
void func_public1(void) {}
void func_public2(void) {}

if you request completions for func_ in other.c you get all the completions:

enter image description here

however, if you open another file and request completions for func_ you only get the public ones (non-static):

enter image description here

Now, in the other file, if you select func_public1, then you can CDT automatically add in the header file for it. You can do this with "organizing imports" Shift-Ctrl-O (Source menu -> Organize Imports).

You can control the behaviour of Organize Imports in the preferences (C/C++ -> Code Style -> Organize Imports)

enter image description here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment