27 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \2// RUN: -verify %s3 4// This example uncovered a bug in UnsafeBufferUsage.cpp, where the5// code assumed that a CXXMethodDecl always have an identifier.6 7int printf( const char* format, char *); // <-- Fake decl of `printf`; to reproduce the bug, this example needs an implicit cast within a printf call.8 9namespace std { // fake std namespace; to reproduce the bug, a CXXConversionDecl needs to be in std namespace.10 class X {11 char * p;12 public: 13 operator char*() {return p;}14 };15 16 class Y {17 public:18 X x;19 };20 21}22 23void test(std::Y &y) {24 // Here `y.x` involves an implicit cast and calls the overloaded cast operator, which has no identifier:25 printf("%s", y.x); // expected-warning{{function 'printf' is unsafe}} expected-note{{}}26}27