[PATCH] D79895: Add a new warning to warn when passing uninitialized variables as const reference parameters to a function
Zequan Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 19 12:03:02 PDT 2020
zequanwu marked an inline comment as done.
zequanwu added a comment.
In D79895#2042992 <https://reviews.llvm.org/D79895#2042992>, @xbolva00 wrote:
> Can you provide some compile time data with warning enabled/disabled?
I compiled the test case with warning enabled and disabled. Since it is controlled by `-Wuninitialzed`, it will diagnose when the flag is given.
$ clang -ftime-report -fsyntax-only warn-uninitialized-const-reference.cpp
===-------------------------------------------------------------------------===
Clang front-end time report
===-------------------------------------------------------------------------===
Total Execution Time: 0.0094 seconds (0.0094 wall clock)
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0091 (100.0%) 0.0003 (100.0%) 0.0094 (100.0%) 0.0094 (100.0%) Clang front-end timer
0.0091 (100.0%) 0.0003 (100.0%) 0.0094 (100.0%) 0.0094 (100.0%) Total
$ clang -ftime-report -Wuninitialized -fsyntax-only warn-uninitialized-const-reference.cpp
===-------------------------------------------------------------------------===
Clang front-end time report
===-------------------------------------------------------------------------===
Total Execution Time: 0.0131 seconds (0.0131 wall clock)
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0046 (100.0%) 0.0086 (100.0%) 0.0131 (100.0%) 0.0131 (100.0%) Clang front-end timer
0.0046 (100.0%) 0.0086 (100.0%) 0.0131 (100.0%) 0.0131 (100.0%) Total
$ clang -ftime-report -Wuninitialized -Wno-uninitialized-const-reference -fsyntax-only warn-uninitialized-const-reference.cpp
===-------------------------------------------------------------------------===
Clang front-end time report
===-------------------------------------------------------------------------===
Total Execution Time: 0.0109 seconds (0.0109 wall clock)
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0073 (100.0%) 0.0036 (100.0%) 0.0109 (100.0%) 0.0109 (100.0%) Clang front-end timer
0.0073 (100.0%) 0.0036 (100.0%) 0.0109 (100.0%) 0.0109 (100.0%) Total
================
Comment at: clang/test/SemaCXX/warn-uninitialized-const-reference.cpp:23
+ int k = const_use(k); // expected-warning {{variable 'k' is uninitialized when used within its own initialization}}
+ A a2 = const_use_A(a2); // expected-warning {{variable 'a2' is uninitialized when used within its own initialization}}
+ A a3(const_ref_use_A(a3)); // expected-warning {{variable 'a3' is uninitialized when passes as a const reference parameter here}}
----------------
zequanwu wrote:
> aeubanks wrote:
> > For my knowledge, is this to make sure that this other warning takes precedence over the one introduced in this change? If it is, a comment would be nice.
> No, original behavior of `-Wuninitialized` for line 24 is silence. Now the new warning will be emitted because it is const use of uninitialized variable.
I meant "const reference use". It was typo.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79895/new/
https://reviews.llvm.org/D79895
More information about the cfe-commits
mailing list