[PATCH] D89380: [clang-tidy] Fix for cppcoreguidelines-prefer-member-initializer to handle classes declared in macros

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 28 17:45:20 PST 2021


alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.
Herald added a subscriber: shchenz.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:6
+//        of this test file) is the macro itself and the spelling location is
+//        <scratch space>:6:1 for some strange reason. This results this warning
+//        to be placed at the very beginning of the message list.
----------------
"results in ..."


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:6
+//        of this test file) is the macro itself and the spelling location is
+//        <scratch space>:6:1 for some strange reason. This results this warning
+//        to be placed at the very beginning of the message list.
----------------
alexfh wrote:
> "results in ..."
The reason is that token pasting is used in the macro. There is no place in any of the existing source files where the text of the token that is created by token pasting exists (verbatim and contiguously).


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:7
+//        <scratch space>:6:1 for some strange reason. This results this warning
+//        to be placed at the very beginning of the message list.
+
----------------
"being"?


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:500
+// CHECK-MESSAGES: :[[@LINE-1]]:54: warning: 'i' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: #define MACRO1 struct InMacro1 { int i; InMacro1() : i(0) { } };
+MACRO1
----------------
Please add CHECK-FIXES: for the macro usage (unchanged, I suppose?). Same below.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:514-515
+#define MACRO4(field) struct InMacro4 { int field; InMacro4() { field = 0; } };
+// C_HECK-MESSAGES: :[[@LINE-1]]:65: warning: 'field' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// C_HECK-FIXES: #define MACRO4(field) struct InMacro4 { int field; InMacro4() : field(0) { } };
+MACRO4(q)
----------------
Do we need these disabled check lines? If so, please mention the reason in a comment.

Same below.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89380/new/

https://reviews.llvm.org/D89380



More information about the cfe-commits mailing list