GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
testsuite

Add Reduced Test For -fanalyzer On std::string

A new test case was added to verify the fix for a false positive in the static analyzer related to std::string.

This commit adds a new test case to the GCC testsuite to verify that a recently-introduced fix to the static analyzer is working correctly. The test is based on a reduced version of libstdc++ code, focusing on the small string optimization of std::string. The original bug caused the analyzer to report false positives due to confusion between small-string-optimization and heap allocation branches.

In Details

This adds g++.dg/analyzer/torture/std-string-pr125304.C to verify the fix for a false positive in the analyzer related to std::string's SSO. The test makes _M_is_local() public to directly test the branching behaviour. This is relevant to toolchain devs because it validates the analyzer's ability to reason about complex C++ standard library features.

For Context

GCC's static analyzer can detect potential bugs at compile time, before a program is even run. This commit adds a new test for the analyzer, specifically targeting the std::string class in C++. std::string sometimes stores short strings directly within the object itself (small string optimization), and sometimes allocates memory on the heap. The test checks for a fix where the analyzer was incorrectly reporting issues due to confusion between these two storage methods. A correct analyzer avoids wasting developer time on false alarms.

Filed Under: testsuiteanalyzerstd::string