llvm-project/clang/test/Analysis/getline-cpp.cpp
NagyDonat e1d4ddb0c6
Reapply "[analyzer] Accept C library functions from the std namespace" again (#85791)
This reapplies 80ab8234ac309418637488b97e0a62d8377b2ecf again, after
fixing a name collision warning in the unit tests (see the revert commit
13ccaf9b9d4400bb128b35ff4ac733e4afc3ad1c for details).

In addition to the previously applied changes, this commit also clarifies the
code in MallocChecker that distinguishes POSIX "getline()" and C++ standard
library "std::getline()" (which are two completely different functions). Note
that "std::getline()" was (accidentally) handled correctly even without this
clarification; but it's better to explicitly handle and test this corner case.

---------

Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
2024-03-25 12:43:51 +01:00

16 lines
557 B
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection -verify %s
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,alpha.unix,debug.ExprInspection -verify %s
//
// expected-no-diagnostics
#include "Inputs/system-header-simulator-cxx.h"
void test_std_getline() {
std::string userid, comment;
// MallocChecker should not confuse the POSIX function getline() and the
// unrelated C++ standard library function std::getline.
std::getline(std::cin, userid, ' '); // no-crash
std::getline(std::cin, comment); // no-crash
}