Skip to content
PaskalCPP
Build and run

Diagnostics

Errors speak PaskalCPP. A mistake in PaskalCPP code is reported in PaskalCPP's words and types; what only C++ can judge is clang's or the linker's report, mapped back to the .pcpp file, line and column it came from.

Who reports a mistake

Every code names the part of the compiler that reports it:

PrefixReported by
LXthe lexer
PRthe parser
CDthe conditional directives (@ifdef and the others)
SMsemantics
ASthe module registry (two modules of one name)
EMthe emitter
ZBthe build driver and the toolchain
CMPthe compiler
DBthe debugger

The reference lists every code with its messages.

  • A mistake on a PaskalCPP construct is reported by PaskalCPP: an unterminated string is LX0001, a missing ; PR0001 (expected ';', found 'LN'), a string assigned to an int32 SM0200, a call no overload takes SM0402.
  • What only C++ can judge is the toolchain's diagnostic, code ZB0016, with clang's or the linker's own message, mapped back to the .pcpp file, line and column: a bare name no declaration has (it may be a C/C++ name: use of undeclared identifier 'LMissing'), a mistake in mixed C++, a symbol no library defines (at the line that calls it). Both targets print the same.
  • A check the compiler writes into the C++ for what clang decides (alignment, packed and overlay fields, printing a C/C++ value) is reported with its SM code, in PaskalCPP's words, at the PaskalCPP construct.
  • clang's warnings are reported on a build that succeeds too, as warnings located in the .pcpp file.
  • They are reported again when nothing changed and zig reuses a file's compile from its cache: pcpp keeps each compile's diagnostics in pcpp-diag\store\ and replays them, so a rebuild reports what the first build did. When the kept diagnostics cannot be opened, kept or restored, that is the warning ZB0036, and the build goes on.
  • A clang diagnostic with no location of its own about a file @addsourcefile adds (an LLVM IR file whose target triple clang overrides) is reported at that @addsourcefile.
  • A linker message with no location about the file of a library the build links is reported where the source names that library, at its @linklibrary or external clause: a text file named bogus.lib is linkbad.pcpp(4,14) ZB0016: <path>\bogus.lib: unknown file type, at the @linklibrary "bogus" value.
errorSM0200…/samples/diagnostics_narrowing.pcpp(33,13)
'int32' does not convert implicitly to 'int8'; write int8(LBig)

How a report prints

A report is one line, [<LABEL>] <file>(<line>,<column>) <CODE>: <message>. The label is HINT, WARN, ERROR or FATAL (cyan, yellow, red and magenta on a console), and the file is its full path with forward slashes.

A note explains the report above it, indented two spaces: <file>(<line>,<column>): Note: <message>. SM0402, for example, gets one note per overload.

errorSM0324…/samples/diagnostics_overload_repeat.pcpp(34,1)
'Show' is already declared with these parameter types: overloads differ in their parameter types …/samples/diagnostics_overload_repeat.pcpp(29,1): note: the first declaration of 'Show' with these parameter types
  • Columns are printed in UTF-16 units, as the editor, VS Code and the language server count them, for PaskalCPP's reports and clang's mapped ones alike.
  • A place with no column (the linker knows only the line) prints column 0: (4,0).
  • Hints and warnings print as they are made, with their notes, between the build's status lines. Errors print together at the end, then Failed., and pcpp exits 1. A build zig ran says Build failed with exit code <n>. first.

Hints and warnings never fail a build: the program builds and runs.

diagnostics_warnings.pcpp
module exe diagnostics_warnings;

@message hint "diagnostics_warnings: a hint";
@message warn "diagnostics_warnings: a warning";

begin
  println("octal {}", 010);
  println("escape {}", "a\qb");
end.
output on x86_64-windows-gnu and x86_64-linux-gnu
octal 8
escape aqb
[Heap] Allocs: 0, Frees: 0, Leaked: 0

How many reports a build shows

pcpp stops at the first error: its budget is one error, and clang is asked for one error per C++ file (-Wfatal-errors); a budget above one asks clang for that many (-ferror-limit=<n>). The language server checks with a budget of 100.

  • Only errors spend the budget: hints and warnings are always kept, and a fatal is kept past the budget.
  • Nothing is emitted or built after a PaskalCPP error: the report comes right after Compiling <file>, with no target or build lines.

One mistake, one report

  • A diagnostic is reported once per build: the same file, line, column, level and message from a header several C++ files include is the first file's report, with its notes.
  • What PaskalCPP has judged, clang never judges again: an unknown escape in a plain string is PR0021 and in a char PR0064, once, and the program gets the character itself ("a\qb" prints aqb).
  • The line splice and comment warnings (LX0201 to LX0203) are the lexer's; clang's copies of them in the .pcpp file are dropped, so a build shows each once, on both targets.
  • With a budget above 1 (the language server's), a statement the parser refuses is reported once and skipped as one piece (a C++ switch or try through its braces, a break, a stray else), and the statement after it is still parsed and checked.
  • One parse nests at most 256 levels, statements and expressions counted together; one level more is PR0042 at the token that would open it, and the parse goes on. A refused block is skipped whole, its own end with it.

When a file or pcpp itself fails

  • A source file that cannot be read is LX0012; a module folder (one @addmodulepath names, or the standard library folder) that cannot be resolved is PR0056.
  • An output folder that cannot be created is EM0001, a generated file that cannot be written EM0002; nothing is built after either.
  • pcpp-output.json that cannot be written is the warning CMP0005: the build goes on, but pcpp --clean will refuse that folder (see Cleaning an output folder).
  • A bug in pcpp itself is reported, never a crash: EM0003 inside the emitter (at the module), the fatal CMP0003 anywhere else. Either is worth reporting as an issue.
  • The VC codes come from pcpp's startup check of its own token tables: VC0001, VC0002, VC0003 and VC0004 are fatal, and only a broken build of pcpp can show one.
  • The language server's formatter refuses a run that fails inside with FM0001, and changes nothing.
  • The build driver's codes are on When the build driver fails, the debugger's on The debugger's own reports, the test suite's on The suite's own reports.