[PATCH] D52218: Warn on self-initializations
Richard Trieu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 17 19:42:49 PDT 2018
rtrieu created this revision.
Improve some diagnostics around self-initialization. The uninitialized checker does not warn on self-initialization, but does warn later if the variable is used. GCC also has a -Winit-self which will enable a -Wuninitialized warning for self-initialized. -Winit-self is active in -Wall
There's also the matter of the variable being const. GCC -Wuninitialized will warn on a const self-initialized with or without -Winit-self.
This patch will make it so that const self-initialization is always warned on under -Wuninitialized. Since Clang does not use warning flags to control other warnings, -Winit-self will be a new warning group for non-const self-initialized. -Winit-self will also be in -Wall via -Wmost.
// GCC - warn with -Wuninitialized and -Winit-self
// Clang - no warning
// Clang with patch - warn with -Winit-self
void f1() {
int x = x;
}
// GCC - warn with -Wuninitialized
// Clang - no warning
// Clang with patch - warn with -Wuninitialized
void f2() {
const int x = x;
}
https://reviews.llvm.org/D52218
Files:
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/AnalysisBasedWarnings.cpp
lib/Sema/SemaDecl.cpp
test/SemaCXX/uninitialized.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52218.165889.patch
Type: text/x-patch
Size: 5499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180918/756cca4b/attachment.bin>
More information about the cfe-commits
mailing list