[clang-tools-extra] [clang-tidy] fix incorrect hint for InitListExpr in prefer-member-initializer (PR #81560)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 15 04:57:46 PST 2024
================
@@ -616,3 +616,26 @@ class Foo {
#undef INVALID_HANDLE_VALUE
#undef RGB
}
+
+namespace GH77684 {
+struct S1 {
+// CHECK-MESSAGES: :[[@LINE+1]]:16: warning: 'M' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+ S1() : M{} { M = 0; }
+// CHECK-FIXES: S1() : M{0}
+ int M;
+};
+struct S2 {
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: 'M' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+ S2() : M{2} { M = 1; }
+// CHECK-FIXES: S2() : M{1}
+ int M;
+};
+struct T { int a; int b; int c; };
+T v;
+struct S3 {
+// CHECK-MESSAGES: :[[@LINE+1]]:21: warning: 'M' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+ S3() : M{1,2,3} { M = v; }
+// CHECK-FIXES: S3() : M{v}
+ T M;
+};
+}
----------------
5chmidti wrote:
Please add the empty body to the test.
https://github.com/llvm/llvm-project/pull/81560
More information about the cfe-commits
mailing list