Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Latest commit

 

History

History
62 lines (48 loc) · 4.71 KB

README.md

File metadata and controls

62 lines (48 loc) · 4.71 KB

Actions Status

The -Wlifetime warnings implemented in clang

This project contains clang's experimental implementation of the lifetime safety profile of the C++ core guidelines.

You can try this implementation on Compiler Explorer by choosing the clang version experimental -Wlifetime.

Warning flags

  • -Wdangling-gsl: Statement-local analysis (enabled by default)
  • -Wreturn-stack-address: Statement-local analysis (enabled by default)
  • -Wlifetime: Main flow-sensitive analysis
  • -Wlifetime-filter: Reduce the number of false-postives at the cost of additional false negatives.
  • -Wno-lifetime-null: Disable flow-sensitive warnings about nullness of Pointers
  • -Wlifetime-global: Flow-sensitive analysis that requires global variables of Pointer type to always point to variables with static lifetime
  • -Wlifetime-disabled: Get warnings when the flow-sensitive analysis is disabled on a function due to forbidden constructs (reinterpret_cast or pointer arithmetic)

Suppress Warnings

Build

You can either try it on Compiler Explorer, or build clang yourself:

mkdir build
cd build 
cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang
make
# Run the tests (optional)
make check-clang 
# Use clang
./bin/clang++ <some-source> <warning-flags>

Further information

The specification

CppCon 2019 Talk, focusing on statement local analysis

EuroLLVM 2019 Talk, focusing on flow-sensitive analysis

CppCon 2018 Talk, focusing on flow-sensitive analysis

CppCon 2018 Keynote, by Herb Sutter

CppCon 2015 Keynote, by Herb Sutter, first introduction

Development

Tests:

Implementation: