Is there a way to see C++ compile warnings in VS Code?

With VS Code the Terminal output is sanitized to only show the progress of the build (phase it’s in and percentage) and any errors that it finds. Is if there’s a way to see compiler warnings?

For example, we added a parameter to a command and didn’t update all of the places where it was called. The code happily compiled and ran until we actually hit that case and then got unexpected behavior.

1 Like

If it compiled, and only failed at runtime, then it’s possible that no warning was flagged for that behavior, as it was valid code.

True. Though I’m looking at this from a generic perspective. My thought process:

  • Ignoring warnings is bad practice.
  • There is no way that a dozen students wrote warning-free code (I write code professionally and I generate and fix plenty of warnings).
  • I’ve never seen a warning with VS Code, therefore it’s hiding them, which is bad.

The build message does actually show warnings when they occur, it’s just that the default build does not include Wall or Werror, so not that many warnings actually get generated.

3 Likes

Ah. That would do it. And that begs the next question:

How do we add the -Wall flag?

I found an args section in build/vscodeconfig.json but that’s a generated file that gets re-written on build.

In build.gradle, inside the model block, add the following

    binaries {
        all {
            if (it.targetPlatform.operatingSystem.isLinux()) {
                it.cppCompiler.args  << 'Wall' << 'Wextra'
            }
        }
    }

That should enable warnings and extra warnings.

1 Like

Just one small thing missing. Should be -Wall and -Wextra

it.cppCompiler.args << ‘-Wall’ << ‘-Wextra’

Other than that. Exactly what I needed. Thanks!