[clang] [-Wunsafe-buffer-usage] Fix a bug that wrongly assumed CXXMethodDecl always has an identifier (PR #137248)
Jan Korous via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 15:17:10 PDT 2025
================
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \
+// RUN: -verify %s
+
+// This example uncovered a bug in UnsafeBufferUsage.cpp, where the
+// code assumed that a CXXMethodDecl always have an identifier.
+
+int printf( const char* format, char *); // <-- Fake decl of `printf`; to reproduce the bug, this example needs an implicit cast within a printf call.
+
+namespace std { // fake std namespace; to reproduce the bug, a CXXConversionDecl needs to be in std namespace.
+ class X {
+ char * p;
+ public:
+ operator char*() {return p;}
+ };
+
+ class Y {
+ public:
+ X x;
+ };
+
+}
+
+void test(std::Y &y) {
+ // Here `y.x` involves an implicit cast and calls the conversion overloading, which has no identifier:
----------------
jkorous-apple wrote:
nit: "calls the overloaded cast operator"
https://github.com/llvm/llvm-project/pull/137248
More information about the cfe-commits
mailing list