[clang] [clang] Restrict -Wnrvo to C++ code only. (PR #157059)
Javier Muñoz Kirschberg via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 8 15:52:33 PDT 2025
================
@@ -0,0 +1,41 @@
+// RUN: %clang -std=c23 -Wnrvo -Xclang -verify %s
+// expected-no-diagnostics
+
+#include <stdlib.h>
+
+#define SIZE 20
+
+typedef struct String_s {
+ char* buf;
+ size_t len;
+} String;
+
+
+void clean(String* s) {
+ free(s->buf);
+}
+
+String randomString() {
+ String s = {};
+
+ s.buf = malloc(SIZE);
+ s.len = SIZE;
+
+ if (!s.buf) {
+ goto fail;
+ }
+
+ return s;
+
+fail:
+ clean(&s);
+ return (String){};
+}
+
+int main(int argc, char** argv)
+{
+ String s= randomString();
+ clean(&s);
+
+ return 0;
+}
----------------
javiermunozkirschberg wrote:
I'll fix this, thanks!
https://github.com/llvm/llvm-project/pull/157059
More information about the cfe-commits
mailing list