This repository demonstrates how to use GitHub Actions problem matchers with Clang compiler diagnostics.
.github/clang-problem-matcher.json- Basic problem matcher for Clang errors/warnings.github/clang-multiline-matcher.json- Enhanced matcher that handles multi-line output with code context.github/workflows/test-clang-matcher.yml- GitHub Actions workflow that tests the problem matchersrc/test.cpp- C++ file with intentional errors to trigger Clang diagnostics
To test the Clang output locally:
clang++ -Wall -Werror -std=c++17 src/test.cpp -o testThis will produce errors similar to:
- Unknown sanitizer attribute warning/error
- Undefined variable error
The problem matcher uses regex patterns to parse Clang output in the format:
file.cpp:line:column: severity: message [error-code]
line | source code
| ^~~~
The matcher extracts:
- File path
- Line number
- Column number
- Severity (error/warning/note)
- Error message
- Error code (e.g., -Wunknown-sanitizers)
To use the problem matcher in your GitHub Actions workflow:
- Add the matcher JSON file to
.github/directory - Enable it with:
echo "::add-matcher::.github/clang-problem-matcher.json" - Run your Clang compilation
- Disable it with:
echo "::remove-matcher owner=clang::"
- Push this repository to GitHub
- The workflow will run automatically on push
- Check the Actions tab to see the annotations created by the problem matcher
- Errors will be shown inline in pull requests