[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-22 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/92241

From 44ae41f00064dc477db0eb00b45fceff811cadec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Mon, 29 Apr 2024 12:49:59 +0200
Subject: [PATCH 1/5] [clang-tidy] Use C-style casts on C23 in
 readability-implicit-bool-conversion

readability-implicit-bool-conversion supports language-versions which has
LangOpts.Bool and that includes C23. The problem is that the fixer suggests
`static_cast<>()` which is not available in C23.

Update checker to provide C-style casts when running on other than C++.
---
 .../ImplicitBoolConversionCheck.cpp   |   6 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../readability/implicit-bool-conversion.rst  |   4 +-
 .../readability/implicit-bool-conversion.c| 333 ++
 4 files changed, 343 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 74152c6034510..c2d1bc691d58a 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -165,6 +165,12 @@ bool needsSpacePrefix(SourceLocation Loc, ASTContext 
&Context) {
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
+  if (!Context.getLangOpts().CPlusPlus) {
+Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(),
+   (Twine("(") + OtherType + ")").str());
+return;
+  }
+
   const Expr *SubExpr = Cast->getSubExpr();
   const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
   const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19f8307412956..d19f83793a6c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
-  fixed problem with duplicate parentheses in double implicit casts.
+  fixed problem with duplicate parentheses in double implicit casts. Corrected
+  the fix suggestions for C23 by using C-style casts instead of 
``static_cast``.
 
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
index 1ea67a0b55e96..643af488ae3df 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
@@ -96,8 +96,8 @@ The rules for generating fix-it hints are:
   - ``if (!pointer)`` is changed to ``if (pointer == nullptr)``,
 
 - in case of conversions from bool to other built-in types, an explicit
-  ``static_cast`` is proposed to make it clear that a conversion is taking
-  place:
+  ``static_cast`` (or a C-style cast for C23) is proposed to make it clear that
+  a conversion is taking place:
 
   - ``int integer = boolean;`` is changed to
 ``int integer = static_cast(boolean);``,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
new file mode 100644
index 0..c264372efaf25
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -0,0 +1,333 @@
+// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t -- -- 
-std=c23
+
+#undef NULL
+#define NULL 0L
+
+void functionTakingBool(bool);
+void functionTakingInt(int);
+void functionTakingUnsignedLong(unsigned long);
+void functionTakingChar(char);
+void functionTakingFloat(float);
+void functionTakingDouble(double);
+void functionTakingSignedChar(signed char);
+
+
+// Implicit conversion from bool.
+
+void implicitConversionFromBoolSimpleCases() {
+  bool boolean = true;
+
+  functionTakingBool(boolean);
+
+  functionTakingInt(boolean);
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: implicit conversion 'bool' -> 
'int' [readability-implicit-bool-conversion]
+  // CHECK-FIXES: functionTakingInt((int)boolean);
+
+  functionTakingUnsignedLong(boolean);
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: implicit conversion 'bool' -> 
'unsigned long'
+  // CHECK-FIXES: functionTakingUnsignedLong((unsigned long)boolean);
+
+  function

[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-16 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/92241

From 44ae41f00064dc477db0eb00b45fceff811cadec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Mon, 29 Apr 2024 12:49:59 +0200
Subject: [PATCH 1/4] [clang-tidy] Use C-style casts on C23 in
 readability-implicit-bool-conversion

readability-implicit-bool-conversion supports language-versions which has
LangOpts.Bool and that includes C23. The problem is that the fixer suggests
`static_cast<>()` which is not available in C23.

Update checker to provide C-style casts when running on other than C++.
---
 .../ImplicitBoolConversionCheck.cpp   |   6 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../readability/implicit-bool-conversion.rst  |   4 +-
 .../readability/implicit-bool-conversion.c| 333 ++
 4 files changed, 343 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 74152c6034510..c2d1bc691d58a 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -165,6 +165,12 @@ bool needsSpacePrefix(SourceLocation Loc, ASTContext 
&Context) {
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
+  if (!Context.getLangOpts().CPlusPlus) {
+Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(),
+   (Twine("(") + OtherType + ")").str());
+return;
+  }
+
   const Expr *SubExpr = Cast->getSubExpr();
   const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
   const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19f8307412956..d19f83793a6c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
-  fixed problem with duplicate parentheses in double implicit casts.
+  fixed problem with duplicate parentheses in double implicit casts. Corrected
+  the fix suggestions for C23 by using C-style casts instead of 
``static_cast``.
 
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
index 1ea67a0b55e96..643af488ae3df 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
@@ -96,8 +96,8 @@ The rules for generating fix-it hints are:
   - ``if (!pointer)`` is changed to ``if (pointer == nullptr)``,
 
 - in case of conversions from bool to other built-in types, an explicit
-  ``static_cast`` is proposed to make it clear that a conversion is taking
-  place:
+  ``static_cast`` (or a C-style cast for C23) is proposed to make it clear that
+  a conversion is taking place:
 
   - ``int integer = boolean;`` is changed to
 ``int integer = static_cast(boolean);``,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
new file mode 100644
index 0..c264372efaf25
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -0,0 +1,333 @@
+// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t -- -- 
-std=c23
+
+#undef NULL
+#define NULL 0L
+
+void functionTakingBool(bool);
+void functionTakingInt(int);
+void functionTakingUnsignedLong(unsigned long);
+void functionTakingChar(char);
+void functionTakingFloat(float);
+void functionTakingDouble(double);
+void functionTakingSignedChar(signed char);
+
+
+// Implicit conversion from bool.
+
+void implicitConversionFromBoolSimpleCases() {
+  bool boolean = true;
+
+  functionTakingBool(boolean);
+
+  functionTakingInt(boolean);
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: implicit conversion 'bool' -> 
'int' [readability-implicit-bool-conversion]
+  // CHECK-FIXES: functionTakingInt((int)boolean);
+
+  functionTakingUnsignedLong(boolean);
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: implicit conversion 'bool' -> 
'unsigned long'
+  // CHECK-FIXES: functionTakingUnsignedLong((unsigned long)boolean);
+
+  function

[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-16 Thread Björn Svensson via cfe-commits


@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
-  fixed problem with duplicate parentheses in double implicit casts.
+  fixed problem with duplicate parentheses in double implicit casts. Corrected
+  the fix suggestions for C23 by using C-style casts instead of 
``static_cast``.

bjosv wrote:

The checker should only affect C23 (+later) of all C standards since the 
checker has
```
  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.Bool;
  }
```
C23 is the first C standard with the bool keyword, instead of provided via 
macros, and my understanding is that's what LangOpts.Bool indicates.

https://github.com/llvm/llvm-project/pull/92241
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)

2024-05-15 Thread Björn Svensson via cfe-commits

https://github.com/bjosv created https://github.com/llvm/llvm-project/pull/92241

`readability-implicit-bool-conversion` supports language-versions with 
`LangOpts.Bool` which includes C23.

This PR corrects an issue that the fixer suggests `static_cast<>()` which is 
not available in C23,
and will instead suggest C-style casts on other than C++.

The fixer will also suggest using `nullptr` instead of `0` and avoid a problem 
with recursive fixes on C23.

The recursive issue, a function taking bool and a comparison, is now excluded 
as in C++.
Before change:
```
  functionTakingBool(integer1 == integer2);
 ^
 (   ) != 0

  functionTakingBool((integer1 == integer2) != 0);
 ^
 (  ) != 0
```
```
AST snippet in C23 for functionTakingBool(integer1 == integer2):

  `-CallExpr 0x5bf18d403b58  'void'
`-ImplicitCastExpr 0x5bf18d403b80  'bool' 

  `-BinaryOperator 0x5bf18d403ae8  'int' '=='
|-ImplicitCastExpr 0x5bf18d403ab8  'int' 
...

compared to AST in C++:

  `-CallExpr 0x5815dec42a78  'void'
`-BinaryOperator 0x5815dec429f0  'bool' '=='
  |-ImplicitCastExpr 0x5815dec429c0  'int' 
  ...
```

From 44ae41f00064dc477db0eb00b45fceff811cadec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Mon, 29 Apr 2024 12:49:59 +0200
Subject: [PATCH 1/3] [clang-tidy] Use C-style casts on C23 in
 readability-implicit-bool-conversion

readability-implicit-bool-conversion supports language-versions which has
LangOpts.Bool and that includes C23. The problem is that the fixer suggests
`static_cast<>()` which is not available in C23.

Update checker to provide C-style casts when running on other than C++.
---
 .../ImplicitBoolConversionCheck.cpp   |   6 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../readability/implicit-bool-conversion.rst  |   4 +-
 .../readability/implicit-bool-conversion.c| 333 ++
 4 files changed, 343 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 74152c6034510..c2d1bc691d58a 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -165,6 +165,12 @@ bool needsSpacePrefix(SourceLocation Loc, ASTContext 
&Context) {
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
+  if (!Context.getLangOpts().CPlusPlus) {
+Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(),
+   (Twine("(") + OtherType + ")").str());
+return;
+  }
+
   const Expr *SubExpr = Cast->getSubExpr();
   const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
   const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19f8307412956..d19f83793a6c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -368,7 +368,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
-  fixed problem with duplicate parentheses in double implicit casts.
+  fixed problem with duplicate parentheses in double implicit casts. Corrected
+  the fix suggestions for C23 by using C-style casts instead of 
``static_cast``.
 
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
index 1ea67a0b55e96..643af488ae3df 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
@@ -96,8 +96,8 @@ The rules for generating fix-it hints are:
   - ``if (!pointer)`` is changed to ``if (pointer == nullptr)``,
 
 - in case of conversions from bool to other built-in types, an explicit
-  ``static_cast`` is proposed to make it clear that a conversion is taking
-  place:
+  ``static_cast`` (or a C-style cast for C23) is proposed to make it clear that
+  a conversion is taking place:
 
   - ``int integer = boolean;`` is changed to
 ``int integer = static_cast(boolean);``,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readabili

[clang-tools-extra] [clang-tidy] Enable C23 support in modernize-use-nullptr (PR #89990)

2024-04-24 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/89990

From 5e4df733dbbf830b712c5a22e16173e851736a98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Wed, 24 Apr 2024 22:39:48 +0200
Subject: [PATCH] [clang-tidy] Enable C23 support in modernize-use-nullptr

C23 introduces the nullptr constant similar to C++11 which means that
the checker modernize-use-nullptr can be used on C23 code as well.

See N3042:
https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm
---
 .../clang-tidy/modernize/UseNullptrCheck.h|   2 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   4 +
 .../checks/modernize/use-nullptr.rst  |   2 +-
 .../checkers/modernize/use-nullptr-c23.c  | 139 ++
 .../checkers/modernize/use-nullptr.c  |   2 +-
 5 files changed, 146 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c

diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 6c32a4edb4ff96..f1591bae446579 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -19,7 +19,7 @@ class UseNullptrCheck : public ClangTidyCheck {
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 // FIXME this should be CPlusPlus11 but that causes test cases to
 // erroneously fail.
-return LangOpts.CPlusPlus;
+return LangOpts.CPlusPlus || LangOpts.C23;
   }
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5b1feffb89ea06..caf61f0d1b16b2 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -269,6 +269,10 @@ Changes in existing checks
   don't remove parentheses used in ``sizeof`` calls when they have array index
   accesses as arguments.
 
+- Improved :doc:`modernize-use-nullptr
+  ` check to include support for
+  ``C23``, which also has introduced the ``nullptr`` keyword.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
index 5e1ba858adf3a9..25e17fee0a3d61 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -4,7 +4,7 @@ modernize-use-nullptr
 =
 
 The check converts the usage of null pointer constants (e.g. ``NULL``, ``0``)
-to use the new C++11 ``nullptr`` keyword.
+to use the new C++11 and C23 ``nullptr`` keyword.
 
 Example
 ---
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
new file mode 100644
index 00..6fb879b91e41c1
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -std=c23
+
+#define NULL 0
+
+void test_assignment() {
+  int *p1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: int *p1 = nullptr;
+  p1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+  // CHECK-FIXES: p1 = nullptr;
+
+  int *p2 = NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+  // CHECK-FIXES: int *p2 = nullptr;
+
+  p2 = p1;
+  // CHECK-FIXES: p2 = p1;
+
+  const int null = 0;
+  int *p3 = &null;
+
+  p3 = NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+  // CHECK-FIXES: p3 = nullptr;
+
+  int *p4 = p3;
+
+  int i1 = 0;
+
+  int i2 = NULL;
+
+  int i3 = null;
+
+  int *p5, *p6, *p7;
+  p5 = p6 = p7 = NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: p5 = p6 = p7 = nullptr;
+}
+
+void test_function(int *p) {}
+
+void test_function_no_ptr_param(int i) {}
+
+void test_function_call() {
+  test_function(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+  // CHECK-FIXES: test_function(nullptr);
+
+  test_function(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+  // CHECK-FIXES: test_function(nullptr);
+
+  test_function_no_ptr_param(0);
+}
+
+char *test_function_return1() {
+  return 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+  // CHECK-FIXES: return nullptr;
+}
+
+void *test_function_return2() {
+  return NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+  // CHECK-FIXES: return nullptr;
+}
+
+int test_function_return4() {
+  return 0;
+}
+
+int test_function_return5() {
+  return NULL;

[clang-tools-extra] [clang-tidy] Enable C23 support in modernize-use-nullptr (PR #89990)

2024-04-24 Thread Björn Svensson via cfe-commits

https://github.com/bjosv created https://github.com/llvm/llvm-project/pull/89990

C23 introduces the `nullptr` constant similar to C++11 which means that the 
checker `modernize-use-nullptr` can be used on C23 code as well.

This PR enables the checker to be run on C23 and adds testcases.

See N3042:
https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm

From 6e4e72cc371a5607616546c7b2ed7bf8386acd4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Wed, 24 Apr 2024 22:39:48 +0200
Subject: [PATCH] [clang-tidy] Enable C23 support in modernize-use-nullptr

C23 introduces the nullptr constant similar to C++11 which means that
the checker modernize-use-nullptr can be used on C23 code as well.

See N3042:
https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm
---
 .../clang-tidy/modernize/UseNullptrCheck.h|   2 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   4 +
 .../checks/modernize/use-nullptr.rst  |   2 +-
 .../checkers/modernize/use-nullptr-c23.c  | 139 ++
 .../checkers/modernize/use-nullptr.c  |   2 +-
 5 files changed, 146 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c

diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 6c32a4edb4ff96..f1591bae446579 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -19,7 +19,7 @@ class UseNullptrCheck : public ClangTidyCheck {
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 // FIXME this should be CPlusPlus11 but that causes test cases to
 // erroneously fail.
-return LangOpts.CPlusPlus;
+return LangOpts.CPlusPlus || LangOpts.C23;
   }
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7095c56fe6..953453219221e8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -253,6 +253,10 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`modernize-use-nullptr
+  ` check to include support for
+  ``C23``, which also has introduced the ``nullptr`` keyword.
+
 - Improved :doc:`modernize-use-using `
   check by adding support for detection of typedefs declared on function level.
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
index 5e1ba858adf3a9..25e17fee0a3d61 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -4,7 +4,7 @@ modernize-use-nullptr
 =
 
 The check converts the usage of null pointer constants (e.g. ``NULL``, ``0``)
-to use the new C++11 ``nullptr`` keyword.
+to use the new C++11 and C23 ``nullptr`` keyword.
 
 Example
 ---
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
new file mode 100644
index 00..6fb879b91e41c1
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
@@ -0,0 +1,139 @@
+// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -std=c23
+
+#define NULL 0
+
+void test_assignment() {
+  int *p1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: int *p1 = nullptr;
+  p1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+  // CHECK-FIXES: p1 = nullptr;
+
+  int *p2 = NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+  // CHECK-FIXES: int *p2 = nullptr;
+
+  p2 = p1;
+  // CHECK-FIXES: p2 = p1;
+
+  const int null = 0;
+  int *p3 = &null;
+
+  p3 = NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+  // CHECK-FIXES: p3 = nullptr;
+
+  int *p4 = p3;
+
+  int i1 = 0;
+
+  int i2 = NULL;
+
+  int i3 = null;
+
+  int *p5, *p6, *p7;
+  p5 = p6 = p7 = NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+  // CHECK-FIXES: p5 = p6 = p7 = nullptr;
+}
+
+void test_function(int *p) {}
+
+void test_function_no_ptr_param(int i) {}
+
+void test_function_call() {
+  test_function(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+  // CHECK-FIXES: test_function(nullptr);
+
+  test_function(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+  // CHECK-FIXES: test_function(nullptr);
+
+  test_function_no_ptr_param(0);
+}
+
+char *test_function_return1() {
+  return 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+  // CHECK-FIXES: return nullptr

[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-08 Thread Björn Svensson via cfe-commits

bjosv wrote:

Thanks for the informative review comments @PiotrZSL, much appreciated.

https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-07 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/73119

From 91cf412abcfd231ab399c3e44c6a9bc14109537c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Tue, 21 Nov 2023 23:30:07 +0100
Subject: [PATCH 1/5] [clang-tidy] Add check hicpp-ignored-remove-result

This check implements the rule 17.5.1 of the HICPP standard
which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of
  std::unique operate by swapping or moving elements of the range they are
  operating over. On completion, they return an iterator to the last valid 
element.
  In the majority of cases the correct behavior is to use this result as the
  first operand in a call to std::erase.

Suppressing issues by casting to `void` is enabled by default, but can be
disabled by setting `AllowCastToVoid` option to `false`.
---
 .../clang-tidy/hicpp/HICPPTidyModule.cpp  | 20 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../checks/hicpp/ignored-remove-result.rst| 20 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/hicpp/ignored-remove-result.cpp  | 47 +++
 5 files changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/hicpp/ignored-remove-result.cpp

diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp 
b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 3749796877120..09d15ccab3f29 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
 #include "../bugprone/UseAfterMoveCheck.h"
 #include "../cppcoreguidelines/AvoidGotoCheck.h"
 #include "../cppcoreguidelines/NoMallocCheck.h"
@@ -41,6 +42,15 @@
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
+namespace {
+
+// Checked functions for hicpp-ignored-remove-result.
+const llvm::StringRef CheckedFunctions = "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;";
+
+} // namespace
+
 namespace clang::tidy {
 namespace hicpp {
 
@@ -64,6 +74,8 @@ class HICPPModule : public ClangTidyModule {
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(
 "hicpp-function-size");
+CheckFactories.registerCheck(
+"hicpp-ignored-remove-result");
 CheckFactories.registerCheck(
 "hicpp-named-parameter");
 CheckFactories.registerCheck(
@@ -107,6 +119,14 @@ class HICPPModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["hicpp-ignored-remove-result.CheckedFunctions"] = CheckedFunctions;
+Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+return Options;
+  }
 };
 
 // Register the HICPPModule using this statically initialized variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc06254..c940025df1c63 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ New check aliases
   ` to 
:doc:`modernize-macro-to-enum
   ` was added.
 
+- New alias :doc:`hicpp-ignored-remove-result
+  ` to 
:doc:`bugprone-unused-return-value
+  ` was added.
+
 Changes in existing checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
new file mode 100644
index 0..4b6188b886db1
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to std::erase.
+
+This check is an alias of check :doc:`bugprone-unused-return-value 
<../bugprone/unused-

[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-07 Thread Björn Svensson via cfe-commits

https://github.com/bjosv edited https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits


@@ -133,6 +133,11 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
 "::boost::system::error_code"))),
   AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
 
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,

bjosv wrote:

Added a constructor that initialized the (missing) CheckedReturnTypes and 
AllowCastToVoid, which is delegated to from the constructor that is used by the 
new checker.
Is this in line with your thoughts?

An alternative is to only have the constructor which sets all members, but I 
thought that looked a bit weird to set AllowCastToVoid twice when constructing 
IgnoredRemoveResultCheck, once when initializing the baseclass and secondly in 
the body to be able to use Options.get (which can't be called in the 
initialization list there).


https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits


@@ -0,0 +1,17 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to ``std::erase``.
+
+Suppressing issues by casting to ``void`` is enabled by default and can be
+disabled by setting `AllowCastToVoid` option to ``false``.

bjosv wrote:

Options part copied from unused-return-value.rst

https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits


@@ -0,0 +1,28 @@
+//===--- IgnoredRemoveResultCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IgnoredRemoveResultCheck.h"
+
+namespace clang::tidy::hicpp {
+
+IgnoredRemoveResultCheck::IgnoredRemoveResultCheck(llvm::StringRef Name,
+   ClangTidyContext *Context)
+: UnusedReturnValueCheck(Name, Context,
+ "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;") {

bjosv wrote:

Removed

https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/73119

From 91cf412abcfd231ab399c3e44c6a9bc14109537c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Tue, 21 Nov 2023 23:30:07 +0100
Subject: [PATCH 1/4] [clang-tidy] Add check hicpp-ignored-remove-result

This check implements the rule 17.5.1 of the HICPP standard
which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of
  std::unique operate by swapping or moving elements of the range they are
  operating over. On completion, they return an iterator to the last valid 
element.
  In the majority of cases the correct behavior is to use this result as the
  first operand in a call to std::erase.

Suppressing issues by casting to `void` is enabled by default, but can be
disabled by setting `AllowCastToVoid` option to `false`.
---
 .../clang-tidy/hicpp/HICPPTidyModule.cpp  | 20 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../checks/hicpp/ignored-remove-result.rst| 20 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/hicpp/ignored-remove-result.cpp  | 47 +++
 5 files changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/hicpp/ignored-remove-result.cpp

diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp 
b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 3749796877120e..09d15ccab3f29c 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
 #include "../bugprone/UseAfterMoveCheck.h"
 #include "../cppcoreguidelines/AvoidGotoCheck.h"
 #include "../cppcoreguidelines/NoMallocCheck.h"
@@ -41,6 +42,15 @@
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
+namespace {
+
+// Checked functions for hicpp-ignored-remove-result.
+const llvm::StringRef CheckedFunctions = "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;";
+
+} // namespace
+
 namespace clang::tidy {
 namespace hicpp {
 
@@ -64,6 +74,8 @@ class HICPPModule : public ClangTidyModule {
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(
 "hicpp-function-size");
+CheckFactories.registerCheck(
+"hicpp-ignored-remove-result");
 CheckFactories.registerCheck(
 "hicpp-named-parameter");
 CheckFactories.registerCheck(
@@ -107,6 +119,14 @@ class HICPPModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["hicpp-ignored-remove-result.CheckedFunctions"] = CheckedFunctions;
+Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+return Options;
+  }
 };
 
 // Register the HICPPModule using this statically initialized variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc062545..c940025df1c63c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ New check aliases
   ` to 
:doc:`modernize-macro-to-enum
   ` was added.
 
+- New alias :doc:`hicpp-ignored-remove-result
+  ` to 
:doc:`bugprone-unused-return-value
+  ` was added.
+
 Changes in existing checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
new file mode 100644
index 00..4b6188b886db12
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to std::erase.
+
+This check is an alias of check :doc:`bugprone-unused-return-value 
<../bugprone/u

[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-05 Thread Björn Svensson via cfe-commits

bjosv wrote:

Updated the check to be derived from the original check instead of an alias.

https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-05 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/73119

From 91cf412abcfd231ab399c3e44c6a9bc14109537c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Tue, 21 Nov 2023 23:30:07 +0100
Subject: [PATCH 1/3] [clang-tidy] Add check hicpp-ignored-remove-result

This check implements the rule 17.5.1 of the HICPP standard
which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of
  std::unique operate by swapping or moving elements of the range they are
  operating over. On completion, they return an iterator to the last valid 
element.
  In the majority of cases the correct behavior is to use this result as the
  first operand in a call to std::erase.

Suppressing issues by casting to `void` is enabled by default, but can be
disabled by setting `AllowCastToVoid` option to `false`.
---
 .../clang-tidy/hicpp/HICPPTidyModule.cpp  | 20 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../checks/hicpp/ignored-remove-result.rst| 20 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/hicpp/ignored-remove-result.cpp  | 47 +++
 5 files changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/hicpp/ignored-remove-result.cpp

diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp 
b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 3749796877120e..09d15ccab3f29c 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
 #include "../bugprone/UseAfterMoveCheck.h"
 #include "../cppcoreguidelines/AvoidGotoCheck.h"
 #include "../cppcoreguidelines/NoMallocCheck.h"
@@ -41,6 +42,15 @@
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
+namespace {
+
+// Checked functions for hicpp-ignored-remove-result.
+const llvm::StringRef CheckedFunctions = "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;";
+
+} // namespace
+
 namespace clang::tidy {
 namespace hicpp {
 
@@ -64,6 +74,8 @@ class HICPPModule : public ClangTidyModule {
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(
 "hicpp-function-size");
+CheckFactories.registerCheck(
+"hicpp-ignored-remove-result");
 CheckFactories.registerCheck(
 "hicpp-named-parameter");
 CheckFactories.registerCheck(
@@ -107,6 +119,14 @@ class HICPPModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["hicpp-ignored-remove-result.CheckedFunctions"] = CheckedFunctions;
+Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+return Options;
+  }
 };
 
 // Register the HICPPModule using this statically initialized variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc062545..c940025df1c63c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ New check aliases
   ` to 
:doc:`modernize-macro-to-enum
   ` was added.
 
+- New alias :doc:`hicpp-ignored-remove-result
+  ` to 
:doc:`bugprone-unused-return-value
+  ` was added.
+
 Changes in existing checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
new file mode 100644
index 00..4b6188b886db12
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to std::erase.
+
+This check is an alias of check :doc:`bugprone-unused-return-value 
<../bugprone/u

[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-11-23 Thread Björn Svensson via cfe-commits

bjosv wrote:

Great, I'll have a go at it to move it into a separate check.
I used `cert-err33-c` as a blueprint and maybe that check can be updated later 
as well if we find a good model.

https://github.com/llvm/llvm-project/pull/73119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-11-23 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/73119

From 91cf412abcfd231ab399c3e44c6a9bc14109537c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Tue, 21 Nov 2023 23:30:07 +0100
Subject: [PATCH 1/2] [clang-tidy] Add check hicpp-ignored-remove-result

This check implements the rule 17.5.1 of the HICPP standard
which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of
  std::unique operate by swapping or moving elements of the range they are
  operating over. On completion, they return an iterator to the last valid 
element.
  In the majority of cases the correct behavior is to use this result as the
  first operand in a call to std::erase.

Suppressing issues by casting to `void` is enabled by default, but can be
disabled by setting `AllowCastToVoid` option to `false`.
---
 .../clang-tidy/hicpp/HICPPTidyModule.cpp  | 20 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../checks/hicpp/ignored-remove-result.rst| 20 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/hicpp/ignored-remove-result.cpp  | 47 +++
 5 files changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/hicpp/ignored-remove-result.cpp

diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp 
b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 3749796877120ed..09d15ccab3f29c2 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
 #include "../bugprone/UseAfterMoveCheck.h"
 #include "../cppcoreguidelines/AvoidGotoCheck.h"
 #include "../cppcoreguidelines/NoMallocCheck.h"
@@ -41,6 +42,15 @@
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
+namespace {
+
+// Checked functions for hicpp-ignored-remove-result.
+const llvm::StringRef CheckedFunctions = "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;";
+
+} // namespace
+
 namespace clang::tidy {
 namespace hicpp {
 
@@ -64,6 +74,8 @@ class HICPPModule : public ClangTidyModule {
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(
 "hicpp-function-size");
+CheckFactories.registerCheck(
+"hicpp-ignored-remove-result");
 CheckFactories.registerCheck(
 "hicpp-named-parameter");
 CheckFactories.registerCheck(
@@ -107,6 +119,14 @@ class HICPPModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["hicpp-ignored-remove-result.CheckedFunctions"] = CheckedFunctions;
+Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+return Options;
+  }
 };
 
 // Register the HICPPModule using this statically initialized variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc0625451..c940025df1c63cd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ New check aliases
   ` to 
:doc:`modernize-macro-to-enum
   ` was added.
 
+- New alias :doc:`hicpp-ignored-remove-result
+  ` to 
:doc:`bugprone-unused-return-value
+  ` was added.
+
 Changes in existing checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
new file mode 100644
index 000..4b6188b886db124
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to std::erase.
+
+This check is an alias of check :doc:`bugprone-unused-return-value 
<../bugp

[lld] [clang-tools-extra] [mlir] [clang] [llvm] [flang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-22 Thread Björn Svensson via cfe-commits


@@ -52,27 +52,42 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+// Matches the expression awaited by the `co_await`.
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,

bjosv wrote:

```suggestion
AST_MATCHER_P(CoawaitExpr, awaitable, ast_matchers::internal::Matcher,
```

https://github.com/llvm/llvm-project/pull/72954
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [lld] [flang] [clang-tools-extra] [clang] [mlir] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-22 Thread Björn Svensson via cfe-commits

https://github.com/bjosv commented:

Nice. Added a naming comment/nit.

https://github.com/llvm/llvm-project/pull/72954
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [llvm] [flang] [lld] [clang-tools-extra] [clang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-22 Thread Björn Svensson via cfe-commits

https://github.com/bjosv edited https://github.com/llvm/llvm-project/pull/72954
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-22 Thread Björn Svensson via cfe-commits


@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//

bjosv wrote:

Removing 3 `-` should make the formatter happy and making it look more like the 
rest of our comment.
```suggestion
//===--- RedundantInlineSpecifierCheck.cpp - clang-tidy ---===//
```

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-22 Thread Björn Svensson via cfe-commits

https://github.com/bjosv commented:

Added some nit/low-prio comments.

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-22 Thread Björn Svensson via cfe-commits


@@ -0,0 +1,35 @@
+.. title:: clang-tidy - readability-redundant-inline-specifier
+
+readability-redundant-inline-specifier
+==
+
+Checks for instances of the `inline` keyword in code where it is redundant
+and recommends its removal.
+
+Examples:
+
+.. code-block:: c++
+
+   constexpr inline void f() {}
+
+In the example abvove the keyword `inline` is redundant since constexpr
+functions are implicitly inlined

bjosv wrote:

```suggestion
In the example above the keyword `inline` is redundant since constexpr
functions are implicitly inlined.
```

https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-22 Thread Björn Svensson via cfe-commits

https://github.com/bjosv edited https://github.com/llvm/llvm-project/pull/73069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-11-22 Thread Björn Svensson via cfe-commits

https://github.com/bjosv created https://github.com/llvm/llvm-project/pull/73119

This check implements the [rule 
17.5.1](https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/standard-library)
 of the HICPP standard which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of 
std::unique operate by swapping or moving elements of the range they are 
operating over. On completion, they return an iterator to the last valid 
element. In the majority of cases the correct behavior is to use this result as 
the first operand in a call to std::erase.

This check is an alias of check `bugprone-unused-return-value` but with a fixed 
set of functions.

Suppressing issues by casting to `void` is enabled by default, but can be 
disabled by setting `AllowCastToVoid` option to `false`.

From 91cf412abcfd231ab399c3e44c6a9bc14109537c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Tue, 21 Nov 2023 23:30:07 +0100
Subject: [PATCH] [clang-tidy] Add check hicpp-ignored-remove-result

This check implements the rule 17.5.1 of the HICPP standard
which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of
  std::unique operate by swapping or moving elements of the range they are
  operating over. On completion, they return an iterator to the last valid 
element.
  In the majority of cases the correct behavior is to use this result as the
  first operand in a call to std::erase.

Suppressing issues by casting to `void` is enabled by default, but can be
disabled by setting `AllowCastToVoid` option to `false`.
---
 .../clang-tidy/hicpp/HICPPTidyModule.cpp  | 20 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../checks/hicpp/ignored-remove-result.rst| 20 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/hicpp/ignored-remove-result.cpp  | 47 +++
 5 files changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/hicpp/ignored-remove-result.cpp

diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp 
b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 3749796877120ed..09d15ccab3f29c2 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
 #include "../bugprone/UseAfterMoveCheck.h"
 #include "../cppcoreguidelines/AvoidGotoCheck.h"
 #include "../cppcoreguidelines/NoMallocCheck.h"
@@ -41,6 +42,15 @@
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
+namespace {
+
+// Checked functions for hicpp-ignored-remove-result.
+const llvm::StringRef CheckedFunctions = "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;";
+
+} // namespace
+
 namespace clang::tidy {
 namespace hicpp {
 
@@ -64,6 +74,8 @@ class HICPPModule : public ClangTidyModule {
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(
 "hicpp-function-size");
+CheckFactories.registerCheck(
+"hicpp-ignored-remove-result");
 CheckFactories.registerCheck(
 "hicpp-named-parameter");
 CheckFactories.registerCheck(
@@ -107,6 +119,14 @@ class HICPPModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["hicpp-ignored-remove-result.CheckedFunctions"] = CheckedFunctions;
+Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+return Options;
+  }
 };
 
 // Register the HICPPModule using this statically initialized variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc0625451..c940025df1c63cd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ New check aliases
   ` to 
:doc:`modernize-macro-to-enum
   ` was added.
 
+- New alias :doc:`hicpp-ignored-remove-result
+  ` to 
:doc:`bugprone-unused-return-value
+  ` was added.
+
 Changes in existing checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
new file mode 100644
index 000..4b6188b886db124
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/

[clang-tools-extra] [clang-tidy][NFC][DOC] Add missing HICPP rule id's (PR #72553)

2023-11-17 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/72553

From 2644f2a71fb144190f67dfd515746f9d185496c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Thu, 16 Nov 2023 18:36:34 +0100
Subject: [PATCH 1/2] [clang-tidy][NFC][DOC] Add missing HICPP rule id's

Add HICPP rule identities to the documentation for `hicpp-avoid-c-arrays`
and `hicpp-no-assembler`.
Includes an update of `hicpp-avoid-goto` to look like other aliased checks.

References:
* avoid-c-arrays
  Commit: 2634bd599567842385e11d1fd70f5486c166f935
---
 .../docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst|  1 +
 .../docs/clang-tidy/checks/hicpp/avoid-goto.rst|  9 +++--
 .../docs/clang-tidy/checks/hicpp/no-assembler.rst  | 10 +-
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst
index 5d125a89e7f4324..789235980ad7b78 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst
@@ -8,3 +8,4 @@ hicpp-avoid-c-arrays
 The hicpp-avoid-c-arrays check is an alias, please see
 :doc:`modernize-avoid-c-arrays <../modernize/avoid-c-arrays>`
 for more information.
+It partly enforces the `rule 4.1.1 
`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
index ffef01ca5d4eb17..91ecaf0594d1f44 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -5,10 +5,7 @@
 hicpp-avoid-goto
 
 
-The `hicpp-avoid-goto` check is an alias to
+The `hicpp-avoid-goto` check is an alias, please see
 :doc:`cppcoreguidelines-avoid-goto <../cppcoreguidelines/avoid-goto>`.
-Rule `6.3.1 High Integrity C++ 
`_
-requires that ``goto`` only skips parts of a block and is not used for other
-reasons.
-
-Both coding guidelines implement the same exception to the usage of ``goto``.
+for more information.
+It enforces the `rule 6.3.1 
`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst
index 381fb365e800ea3..cfc6e9b6ec3477a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst
@@ -1,10 +1,10 @@
 .. title:: clang-tidy - hicpp-no-assembler
 
 hicpp-no-assembler
-===
+==
 
-Check for assembler statements. No fix is offered.
+Checks for assembler statements. Use of inline assembly should be avoided since
+it restricts the portability of the code.
 
-Inline assembler is forbidden by the `High Integrity C++ Coding Standard
-`_
-as it restricts the portability of code.
+This enforces `rule 7.5.1 
`_
+of the High Integrity C++ Coding Standard.

From 009b82f6263616ee96c2de20957d05e135e19b8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Fri, 17 Nov 2023 10:39:32 +0100
Subject: [PATCH 2/2] Fixup: remove overlooked period

---
 clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
index 91ecaf0594d1f44..ccc2a7b34efe540 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -6,6 +6,6 @@ hicpp-avoid-goto
 
 
 The `hicpp-avoid-goto` check is an alias, please see
-:doc:`cppcoreguidelines-avoid-goto <../cppcoreguidelines/avoid-goto>`.
+:doc:`cppcoreguidelines-avoid-goto <../cppcoreguidelines/avoid-goto>`
 for more information.
 It enforces the `rule 6.3.1 
`_.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][DOC] Add missing HICPP rule id's (PR #72553)

2023-11-16 Thread Björn Svensson via cfe-commits

https://github.com/bjosv created https://github.com/llvm/llvm-project/pull/72553

Add HICPP rule identities to the documentation for `hicpp-avoid-c-arrays` and 
`hicpp-no-assembler`.

Includes an update of `hicpp-avoid-goto` to look like other aliased checks.

References:
* avoid-c-arrays 
  Commit: 2634bd599567842385e11d1fd70f5486c166f935

From 2644f2a71fb144190f67dfd515746f9d185496c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Thu, 16 Nov 2023 18:36:34 +0100
Subject: [PATCH] [clang-tidy][NFC][DOC] Add missing HICPP rule id's

Add HICPP rule identities to the documentation for `hicpp-avoid-c-arrays`
and `hicpp-no-assembler`.
Includes an update of `hicpp-avoid-goto` to look like other aliased checks.

References:
* avoid-c-arrays
  Commit: 2634bd599567842385e11d1fd70f5486c166f935
---
 .../docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst|  1 +
 .../docs/clang-tidy/checks/hicpp/avoid-goto.rst|  9 +++--
 .../docs/clang-tidy/checks/hicpp/no-assembler.rst  | 10 +-
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst
index 5d125a89e7f4324..789235980ad7b78 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-c-arrays.rst
@@ -8,3 +8,4 @@ hicpp-avoid-c-arrays
 The hicpp-avoid-c-arrays check is an alias, please see
 :doc:`modernize-avoid-c-arrays <../modernize/avoid-c-arrays>`
 for more information.
+It partly enforces the `rule 4.1.1 
`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
index ffef01ca5d4eb17..91ecaf0594d1f44 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -5,10 +5,7 @@
 hicpp-avoid-goto
 
 
-The `hicpp-avoid-goto` check is an alias to
+The `hicpp-avoid-goto` check is an alias, please see
 :doc:`cppcoreguidelines-avoid-goto <../cppcoreguidelines/avoid-goto>`.
-Rule `6.3.1 High Integrity C++ 
`_
-requires that ``goto`` only skips parts of a block and is not used for other
-reasons.
-
-Both coding guidelines implement the same exception to the usage of ``goto``.
+for more information.
+It enforces the `rule 6.3.1 
`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst
index 381fb365e800ea3..cfc6e9b6ec3477a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-assembler.rst
@@ -1,10 +1,10 @@
 .. title:: clang-tidy - hicpp-no-assembler
 
 hicpp-no-assembler
-===
+==
 
-Check for assembler statements. No fix is offered.
+Checks for assembler statements. Use of inline assembly should be avoided since
+it restricts the portability of the code.
 
-Inline assembler is forbidden by the `High Integrity C++ Coding Standard
-`_
-as it restricts the portability of code.
+This enforces `rule 7.5.1 
`_
+of the High Integrity C++ Coding Standard.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits