-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-tidy] Improve
google-explicit-constructor
checks handling of…
… `explicit(bool)` (#82689) We now treat `explicit(false)` the same way we treat `noexcept(false)` in the noexcept checks, which is ignoring it. Also introduced a new warning message if a constructor has an `explicit` declaration which evaluates to false and no longer emit a faulty FixIt. Fixes #81121
- Loading branch information
Showing
3 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// RUN: %check_clang_tidy %s google-explicit-constructor %t -std=c++20-or-later | ||
|
||
namespace issue_81121 | ||
{ | ||
|
||
static constexpr bool ConstFalse = false; | ||
static constexpr bool ConstTrue = true; | ||
|
||
struct A { | ||
explicit(true) A(int); | ||
}; | ||
|
||
struct B { | ||
explicit(false) B(int); | ||
}; | ||
|
||
struct C { | ||
explicit(ConstTrue) C(int); | ||
}; | ||
|
||
struct D { | ||
explicit(ConstFalse) D(int); | ||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: single-argument constructors explicit expression evaluates to 'false' [google-explicit-constructor] | ||
}; | ||
|
||
template <typename> | ||
struct E { | ||
explicit(true) E(int); | ||
}; | ||
|
||
template <typename> | ||
struct F { | ||
explicit(false) F(int); | ||
}; | ||
|
||
template <typename> | ||
struct G { | ||
explicit(ConstTrue) G(int); | ||
}; | ||
|
||
template <typename> | ||
struct H { | ||
explicit(ConstFalse) H(int); | ||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: single-argument constructors explicit expression evaluates to 'false' [google-explicit-constructor] | ||
}; | ||
|
||
template <int Val> | ||
struct I { | ||
explicit(Val > 0) I(int); | ||
}; | ||
|
||
template <int Val> | ||
struct J { | ||
explicit(Val > 0) J(int); | ||
}; | ||
|
||
void useJ(J<0>, J<100>); | ||
|
||
} // namespace issue_81121 |