[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-30 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Apologies for the late reply, need to fix my mail filter so I don't miss the 
notifications!

IMHO either modernize or readability are suitable categories. Performance can 
vary/be negligible depending on context I suppose?

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

I agree with the opinions from Aaron And Piotr above - this check does the 
opposite of readability: it forces people to waste time digging into the 
Standard to find the quote that says the return is not needed. 

Could some argumentation be provided as to why this would be a good check to 
have? What coding guidelines/best practice articles promote this? I cannot 
think of any category where it would fit (besides misc). 

I believe this is a nano-optimization, and premature optimization is the root 
of all evil :) 

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks for understanding @11happy ! As you say the learning experience is 
invaluable and will be very useful for the next check. All contributions are 
greatly appreciated :)

I can recommend you look into fairly recent issues - older issues may not have 
been reviewed throughly or simply be forgotten.

https://github.com/llvm/llvm-project/pull/77586
___
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] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-16 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Shouldn't we simply `return`?

As you say, the assert is disabled in Release mode. Even if it's enabled, the 
author if `getSubExpr` may one day decide to remove the assert without possibly 
knowing all the places that do rely on that assert, leaving the code 
unprotected. It seems like it's trivial solution to `return` and be on the safe 
side.

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


[clang] [llvm] [clang-tools-extra] [clang-tidy] Remove cert-dcl21-cpp check (PR #80181)

2024-01-31 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/80181

Deprecated since clang-tidy 17. The rule DCL21-CPP has been removed from the 
CERT guidelines, so it does not make sense to keep the check.

Fixes #42788

>From fdb65ef4805152ad143a120e343d696f8b08d3db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 18:53:00 +
Subject: [PATCH] [clang-tidy] Remove cert-dcl21-cpp check

Deprecated since clang-tidy 17. The rule DCL21-CPP has been removed
from the CERT guidelines, so it does not make sense to keep the check.

Fixes #42788
---
 .../clang-tidy/cert/CERTTidyModule.cpp|   3 -
 .../clang-tidy/cert/CMakeLists.txt|   1 -
 .../clang-tidy/cert/PostfixOperatorCheck.cpp  |  80 ---
 .../clang-tidy/cert/PostfixOperatorCheck.h|  34 -
 clang-tools-extra/clangd/TidyFastChecks.inc   |   1 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +
 .../docs/clang-tidy/checks/cert/dcl21-cpp.rst |  28 
 .../docs/clang-tidy/checks/list.rst   |   1 -
 .../clang-tidy/checkers/cert/dcl21-cpp.cpp| 134 --
 clang/docs/tools/clang-formatted-files.txt|   2 -
 .../clang-tidy/cert/BUILD.gn  |   1 -
 11 files changed, 3 insertions(+), 285 deletions(-)
 delete mode 100644 clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp
 delete mode 100644 clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.h
 delete mode 100644 clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cert/dcl21-cpp.cpp

diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp 
b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index d334ab8c437d3..b06a903f92b3e 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -33,7 +33,6 @@
 #include "LimitedRandomnessCheck.h"
 #include "MutatingCopyCheck.h"
 #include "NonTrivialTypesLibcMemoryCallsCheck.h"
-#include "PostfixOperatorCheck.h"
 #include "ProperlySeededRandomGeneratorCheck.h"
 #include "SetLongJmpCheck.h"
 #include "StaticObjectExceptionCheck.h"
@@ -239,8 +238,6 @@ class CERTModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "cert-con54-cpp");
 // DCL
-CheckFactories.registerCheck(
-"cert-dcl21-cpp");
 CheckFactories.registerCheck("cert-dcl50-cpp");
 CheckFactories.registerCheck(
 "cert-dcl51-cpp");
diff --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index 889180f62fde9..882735c9d1e0d 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -12,7 +12,6 @@ add_clang_library(clangTidyCERTModule
   LimitedRandomnessCheck.cpp
   MutatingCopyCheck.cpp
   NonTrivialTypesLibcMemoryCallsCheck.cpp
-  PostfixOperatorCheck.cpp
   ProperlySeededRandomGeneratorCheck.cpp
   SetLongJmpCheck.cpp
   StaticObjectExceptionCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp 
b/clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp
deleted file mode 100644
index 8ff63ade7315d..0
--- a/clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//===--- PostfixOperatorCheck.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 "PostfixOperatorCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang::tidy::cert {
-
-void PostfixOperatorCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(functionDecl(hasAnyOverloadedOperatorName("++", "--"),
-  unless(isInstantiated()))
- .bind("decl"),
- this);
-}
-
-void PostfixOperatorCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
-
-  bool HasThis = false;
-  if (const auto *MethodDecl = dyn_cast(FuncDecl))
-HasThis = MethodDecl->isInstance();
-
-  // Check if the operator is a postfix one.
-  if (FuncDecl->getNumParams() != (HasThis ? 1 : 2))
-return;
-
-  SourceRange ReturnRange = FuncDecl->getReturnTypeSourceRange();
-  SourceLocation Location = ReturnRange.getBegin();
-  if (!Location.isValid())
-return;
-
-  QualType ReturnType = FuncDecl->getReturnType();
-
-  // Warn when the operators return a reference.
-  if (const auto *RefType = ReturnType->getAs()) {
-auto Diag = diag(Location, "overloaded %0 returns a reference inste

[clang] [llvm] [clang-tools-extra] [clang-tidy] Remove cert-dcl21-cpp check (PR #80181)

2024-01-31 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

The code formatting job seems to produce incorrect changes.

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


[clang-tools-extra] [llvm] [clang] [clang-tidy] Remove cert-dcl21-cpp check (PR #80181)

2024-01-31 Thread Carlos Galvez via cfe-commits

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


[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-01-31 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/80193

…refer-member-init

This functionality already exists in
cppcoreguidelines-use-default-member-init. It was deprecated from this check in 
clang-tidy 17.

This allows us to fully decouple this check from the corresponding modernize 
check, which has an unhealthy dependency.

Fixes #62169

>From bfa4ea36a2695ec8d6ea92db588f91d5c818968a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 20:25:27 +
Subject: [PATCH] [clang-tidy] Remove enforcement of rule C.48 from
 cppcoreguidelines-prefer-member-init

This functionality already exists in
cppcoreguidelines-use-default-member-init. It was deprecated from
this check in clang-tidy 17.

This allows us to fully decouple this check from the corresponding
modernize check, which has an unhealthy dependency.

Fixes #62169
---
 .../PreferMemberInitializerCheck.cpp  | 245 ++
 .../PreferMemberInitializerCheck.h|   4 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +
 .../prefer-member-initializer.rst |  54 +---
 ...ize-use-default-member-init-assignment.cpp |  33 ---
 ...izer-modernize-use-default-member-init.cpp |  33 ---
 6 files changed, 100 insertions(+), 277 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index f79a67819bb85..de96c3dc4efef 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
   return Func->isNoReturn();
 }
 
-static bool isLiteral(const Expr *E) {
-  return isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  return false;
-}
-
-static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
-  if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
-return true;
-
-  if (const auto *DRE = dyn_cast(Value))
-return isa(DRE->getDecl());
-
-  return false;
-}
-
 namespace {
 
 AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
@@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const 
Stmt *S,
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IsUseDefaultMemberInitEnabled(
-  Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(
-  Options.get("UseAssignment",
-  OptionsView("modernize-use-default-member-init",
-  Context->getOptions().CheckOptions, Context)
-  .get("UseAssignment", false))) {}
-
-void PreferMemberInitializerCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "UseAssignment", UseAssignment);
-}
+: ClangTidyCheck(Name, Context) {}
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
- " default member initializer")
-  << Field;
-  

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-01-31 Thread Carlos Galvez via cfe-commits


@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
- " default member initializer")
-  << Field;
-  if (InvalidFix)
-continue;
-  CharSourceRange StmtRange =
-  CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
 
-  SmallString<128> Insertion(
-  {UseAssignment ? " = " : "{",
-   Lexer::getSourceText(Result.SourceManager->getExpansionRange(
-InitValue->getSourceRange()),
-*Result.SourceManager, getLangOpts()),
-   UseAssignment ? "" : "}"});
-
-  Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
-   << FixItHint::CreateRemoval(StmtRange);
-
-} else {

carlosgalvezp wrote:

The diff is very unfortunate, but essentially there's no changes to the code 
inside this "else" block. It's just unindented 2 spaces. The main change is the 
removal of the "if" block.

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


[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-02-01 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks for the review! I agree, check names are not the best. It's a bit of a 
hassle to change them though :/ 

I will fix the comment about the release notes tonight :+1: 

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


[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/80193

>From bfa4ea36a2695ec8d6ea92db588f91d5c818968a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 20:25:27 +
Subject: [PATCH 1/2] [clang-tidy] Remove enforcement of rule C.48 from
 cppcoreguidelines-prefer-member-init

This functionality already exists in
cppcoreguidelines-use-default-member-init. It was deprecated from
this check in clang-tidy 17.

This allows us to fully decouple this check from the corresponding
modernize check, which has an unhealthy dependency.

Fixes #62169
---
 .../PreferMemberInitializerCheck.cpp  | 245 ++
 .../PreferMemberInitializerCheck.h|   4 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +
 .../prefer-member-initializer.rst |  54 +---
 ...ize-use-default-member-init-assignment.cpp |  33 ---
 ...izer-modernize-use-default-member-init.cpp |  33 ---
 6 files changed, 100 insertions(+), 277 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index f79a67819bb85..de96c3dc4efef 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
   return Func->isNoReturn();
 }
 
-static bool isLiteral(const Expr *E) {
-  return isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  return false;
-}
-
-static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
-  if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
-return true;
-
-  if (const auto *DRE = dyn_cast(Value))
-return isa(DRE->getDecl());
-
-  return false;
-}
-
 namespace {
 
 AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
@@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const 
Stmt *S,
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IsUseDefaultMemberInitEnabled(
-  Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(
-  Options.get("UseAssignment",
-  OptionsView("modernize-use-default-member-init",
-  Context->getOptions().CheckOptions, Context)
-  .get("UseAssignment", false))) {}
-
-void PreferMemberInitializerCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "UseAssignment", UseAssignment);
-}
+: ClangTidyCheck(Name, Context) {}
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
- " default member initializer")
-  << Field;
-  if (InvalidFix)
-continue;
-  CharSourceRange StmtRange =
-  CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
 
-  SmallString<128> Insertion(
-  {UseAssignment ? " = " : "{",
-

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (PR #80330)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID: 
In-Reply-To:


https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/80330

This functionality already exists in
cppcoreguidelines-use-default-member-init. It was deprecated from this check in 
clang-tidy 17.

This allows us to fully decouple this check from the corresponding modernize 
check, which has an unhealthy dependency.

Fixes https://github.com/llvm/llvm-project/issues/62169

>From e3b3d8b5f8edfd7d8bf759784868431220013a03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 20:25:27 +
Subject: [PATCH 1/2] [clang-tidy] Remove enforcement of rule C.48 from
 cppcoreguidelines-prefer-member-init

This functionality already exists in
cppcoreguidelines-use-default-member-init. It was deprecated from
this check in clang-tidy 17.

This allows us to fully decouple this check from the corresponding
modernize check, which has an unhealthy dependency.

Fixes #62169
---
 .../PreferMemberInitializerCheck.cpp  | 245 ++
 .../PreferMemberInitializerCheck.h|   4 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +
 .../prefer-member-initializer.rst |  54 +---
 ...ize-use-default-member-init-assignment.cpp |  33 ---
 ...izer-modernize-use-default-member-init.cpp |  33 ---
 6 files changed, 100 insertions(+), 277 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index f79a67819bb85..de96c3dc4efef 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
   return Func->isNoReturn();
 }
 
-static bool isLiteral(const Expr *E) {
-  return isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  return false;
-}
-
-static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
-  if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
-return true;
-
-  if (const auto *DRE = dyn_cast(Value))
-return isa(DRE->getDecl());
-
-  return false;
-}
-
 namespace {
 
 AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
@@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const 
Stmt *S,
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IsUseDefaultMemberInitEnabled(
-  Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(
-  Options.get("UseAssignment",
-  OptionsView("modernize-use-default-member-init",
-  Context->getOptions().CheckOptions, Context)
-  .get("UseAssignment", false))) {}
-
-void PreferMemberInitializerCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "UseAssignment", UseAssignment);
-}
+: ClangTidyCheck(Name, Context) {}
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
-   

[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-01 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/80333

…ationFileExtensions

Deprecated since clang-tidy 17. Use the corresponding global options instead.

Fixes #61947

>From fbb0837342a566ff928b211cbb418075a7e744fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 1 Feb 2024 20:00:45 +
Subject: [PATCH] [clang-tidy] Remove check-specific HeaderFileExtensions and
 ImplementationFileExtensions

Deprecated since clang-tidy 17. Use the corresponding global options
instead.

Fixes #61947
---
 .../DynamicStaticInitializersCheck.cpp| 22 +--
 .../bugprone/DynamicStaticInitializersCheck.h | 10 -
 .../bugprone/SuspiciousIncludeCheck.cpp   | 38 ++
 .../bugprone/SuspiciousIncludeCheck.h | 15 ---
 .../google/GlobalNamesInHeadersCheck.cpp  | 22 +--
 .../google/GlobalNamesInHeadersCheck.h| 10 -
 .../google/UnnamedNamespaceInHeaderCheck.cpp  | 22 +--
 .../google/UnnamedNamespaceInHeaderCheck.h| 10 -
 .../misc/DefinitionsInHeadersCheck.cpp| 39 +++
 .../misc/DefinitionsInHeadersCheck.h  |  9 -
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 17 +---
 .../misc/UseAnonymousNamespaceCheck.cpp   | 22 +--
 .../misc/UseAnonymousNamespaceCheck.h | 10 -
 .../clang-tidy/utils/HeaderGuard.cpp  |  4 --
 .../clang-tidy/utils/HeaderGuard.h| 27 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   | 31 +++
 .../checks/bugprone/suspicious-include.rst| 24 
 .../checks/google/build-namespaces.rst| 15 ---
 .../checks/google/global-names-in-headers.rst | 15 ---
 .../clang-tidy/checks/llvm/header-guard.rst   | 15 ---
 .../checks/misc/definitions-in-headers.rst| 24 
 .../checks/misc/unused-using-decls.rst| 16 +---
 .../checks/misc/use-anonymous-namespace.rst   | 16 +---
 23 files changed, 54 insertions(+), 379 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
   }
-  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   voi

[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/80333

>From fbb0837342a566ff928b211cbb418075a7e744fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 1 Feb 2024 20:00:45 +
Subject: [PATCH 1/2] [clang-tidy] Remove check-specific HeaderFileExtensions
 and ImplementationFileExtensions

Deprecated since clang-tidy 17. Use the corresponding global options
instead.

Fixes #61947
---
 .../DynamicStaticInitializersCheck.cpp| 22 +--
 .../bugprone/DynamicStaticInitializersCheck.h | 10 -
 .../bugprone/SuspiciousIncludeCheck.cpp   | 38 ++
 .../bugprone/SuspiciousIncludeCheck.h | 15 ---
 .../google/GlobalNamesInHeadersCheck.cpp  | 22 +--
 .../google/GlobalNamesInHeadersCheck.h| 10 -
 .../google/UnnamedNamespaceInHeaderCheck.cpp  | 22 +--
 .../google/UnnamedNamespaceInHeaderCheck.h| 10 -
 .../misc/DefinitionsInHeadersCheck.cpp| 39 +++
 .../misc/DefinitionsInHeadersCheck.h  |  9 -
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 17 +---
 .../misc/UseAnonymousNamespaceCheck.cpp   | 22 +--
 .../misc/UseAnonymousNamespaceCheck.h | 10 -
 .../clang-tidy/utils/HeaderGuard.cpp  |  4 --
 .../clang-tidy/utils/HeaderGuard.h| 27 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   | 31 +++
 .../checks/bugprone/suspicious-include.rst| 24 
 .../checks/google/build-namespaces.rst| 15 ---
 .../checks/google/global-names-in-headers.rst | 15 ---
 .../clang-tidy/checks/llvm/header-guard.rst   | 15 ---
 .../checks/misc/definitions-in-headers.rst| 24 
 .../checks/misc/unused-using-decls.rst| 16 +---
 .../checks/misc/use-anonymous-namespace.rst   | 16 +---
 23 files changed, 54 insertions(+), 379 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
   }
-  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Res

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (PR #80330)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/80333

>From b40347c8025b0d5de83453012a76d412c07f54a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 1 Feb 2024 20:00:45 +
Subject: [PATCH 1/2] [clang-tidy] Remove check-specific HeaderFileExtensions
 and ImplementationFileExtensions

Deprecated since clang-tidy 17. Use the corresponding global options
instead.

Fixes #61947
---
 .../DynamicStaticInitializersCheck.cpp| 22 +--
 .../bugprone/DynamicStaticInitializersCheck.h | 10 -
 .../bugprone/SuspiciousIncludeCheck.cpp   | 38 ++
 .../bugprone/SuspiciousIncludeCheck.h | 15 ---
 .../google/GlobalNamesInHeadersCheck.cpp  | 22 +--
 .../google/GlobalNamesInHeadersCheck.h| 10 -
 .../google/UnnamedNamespaceInHeaderCheck.cpp  | 22 +--
 .../google/UnnamedNamespaceInHeaderCheck.h| 10 -
 .../misc/DefinitionsInHeadersCheck.cpp| 39 +++
 .../misc/DefinitionsInHeadersCheck.h  |  9 -
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 17 +---
 .../misc/UseAnonymousNamespaceCheck.cpp   | 22 +--
 .../misc/UseAnonymousNamespaceCheck.h | 10 -
 .../clang-tidy/utils/HeaderGuard.cpp  |  4 --
 .../clang-tidy/utils/HeaderGuard.h| 27 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   | 31 +++
 .../checks/bugprone/suspicious-include.rst| 24 
 .../checks/google/build-namespaces.rst| 15 ---
 .../checks/google/global-names-in-headers.rst | 15 ---
 .../clang-tidy/checks/llvm/header-guard.rst   | 15 ---
 .../checks/misc/definitions-in-headers.rst| 24 
 .../checks/misc/unused-using-decls.rst| 16 +---
 .../checks/misc/use-anonymous-namespace.rst   | 16 +---
 23 files changed, 54 insertions(+), 379 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
   }
-  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Res

[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-02 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] b43a2ae - [clang-tidy] Suppress readability-static-access-through-instance for CUDA built-in variables

2021-10-25 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2021-10-26T05:45:25Z
New Revision: b43a2aee4ee946d8897880e824f4b09fe4c46143

URL: 
https://github.com/llvm/llvm-project/commit/b43a2aee4ee946d8897880e824f4b09fe4c46143
DIFF: 
https://github.com/llvm/llvm-project/commit/b43a2aee4ee946d8897880e824f4b09fe4c46143.diff

LOG: [clang-tidy] Suppress readability-static-access-through-instance for CUDA 
built-in variables

clang-tidy can be used to statically analyze CUDA code,
thanks to clang being able to compile CUDA code natively.
This makes clang-tidy the one and only open-source
static analyzer for CUDA.

However it currently warns for native CUDA built-in
variables, like threadIdx, due to the way they
are implemented in clang.

Users don't need to know the details of the clang
implementation, and they should continue to write
idiomatic code. Therefore, suppress the warning
if a CUDA built-in variable is encountered.

Fixes https://bugs.llvm.org/show_bug.cgi?id=48758

Added: 

clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-static-accessed-through-instance/__clang_cuda_builtin_vars.h

Modified: 

clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
index df4a39e11ce43..f2c1b0f5ec49b 100644
--- 
a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -9,6 +9,7 @@
 #include "StaticAccessedThroughInstanceCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
 
 using namespace clang::ast_matchers;
 
@@ -54,7 +55,7 @@ void StaticAccessedThroughInstanceCheck::check(
 
   const Expr *BaseExpr = MemberExpression->getBase();
 
-  // Do not warn for overlaoded -> operators.
+  // Do not warn for overloaded -> operators.
   if (isa(BaseExpr))
 return;
 
@@ -70,6 +71,10 @@ void StaticAccessedThroughInstanceCheck::check(
   std::string BaseTypeName =
   BaseType.getAsString(PrintingPolicyWithSupressedTag);
 
+  // Do not warn for CUDA built-in variables.
+  if (StringRef(BaseTypeName).startswith("__cuda_builtin_"))
+return;
+
   SourceLocation MemberExprStartLoc = MemberExpression->getBeginLoc();
   auto Diag =
   diag(MemberExprStartLoc, "static member accessed through instance");

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-static-accessed-through-instance/__clang_cuda_builtin_vars.h
 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-static-accessed-through-instance/__clang_cuda_builtin_vars.h
new file mode 100644
index 0..63eb17303c6e8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-static-accessed-through-instance/__clang_cuda_builtin_vars.h
@@ -0,0 +1,36 @@
+//===--- __clang_cuda_builtin_vars.h - Stub header for tests *- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef ___CLANG_CUDA_BUILTIN_VARS_H_
+#define ___CLANG_CUDA_BUILTIN_VARS_H_
+
+#define __CUDA_DEVICE_BUILTIN(FIELD) \
+  static unsigned int FIELD;
+
+struct __cuda_builtin_threadIdx_t {
+  __CUDA_DEVICE_BUILTIN(x);
+};
+
+struct __cuda_builtin_blockIdx_t {
+  __CUDA_DEVICE_BUILTIN(x);
+};
+
+struct __cuda_builtin_blockDim_t {
+  __CUDA_DEVICE_BUILTIN(x);
+};
+
+struct __cuda_builtin_gridDim_t {
+  __CUDA_DEVICE_BUILTIN(x);
+};
+
+__cuda_builtin_threadIdx_t threadIdx;
+__cuda_builtin_blockIdx_t blockIdx;
+__cuda_builtin_blockDim_t blockDim;
+__cuda_builtin_gridDim_t gridDim;
+
+#endif // ___CLANG_CUDA_BUILTIN_VARS_H_

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
index 9de96ae3a9d35..cd8d198c3d47d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t
+// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t 
-- -- -isystem %S/Inputs/readability-static-accessed-through-instance
+#include <__clang_cuda_builtin_vars.h>
 
 struct C {
   static void foo();
@@ -248,3 +249,17 @@ void use_inline() {

[clang] 7ecec3f - [CUDA] Bump supported CUDA version to 11.5

2021-11-09 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2021-11-09T08:20:53Z
New Revision: 7ecec3f0f5215c99e45d7000c11230ba2f7e421c

URL: 
https://github.com/llvm/llvm-project/commit/7ecec3f0f5215c99e45d7000c11230ba2f7e421c
DIFF: 
https://github.com/llvm/llvm-project/commit/7ecec3f0f5215c99e45d7000c11230ba2f7e421c.diff

LOG: [CUDA] Bump supported CUDA version to 11.5

Differential Revision: https://reviews.llvm.org/D113249

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/include/clang/Basic/Cuda.h
clang/lib/Basic/Cuda.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
llvm/docs/CompileCudaWithLLVM.rst
llvm/lib/Target/NVPTX/NVPTX.td

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 56ed6d28949f3..fd3217c29e67e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -158,7 +158,7 @@ C++2b Feature Support
 CUDA Language Changes in Clang
 --
 
-- Clang now supports CUDA versions up to 11.4.
+- Clang now supports CUDA versions up to 11.5.
 - Default GPU architecture has been changed from sm_20 to sm_35.
 
 Objective-C Language Changes in Clang

diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 7afee4dbc80bc..025fef05c8e0d 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -41,7 +41,9 @@
 #pragma push_macro("PTX72")
 #pragma push_macro("PTX73")
 #pragma push_macro("PTX74")
-#define PTX74 "ptx74"
+#pragma push_macro("PTX75")
+#define PTX75 "ptx75"
+#define PTX74 "ptx74|" PTX75
 #define PTX73 "ptx73|" PTX74
 #define PTX72 "ptx72|" PTX73
 #define PTX71 "ptx71|" PTX72
@@ -827,3 +829,4 @@ TARGET_BUILTIN(__nvvm_cp_async_wait_all, "v", "", 
AND(SM_80,PTX70))
 #pragma pop_macro("PTX72")
 #pragma pop_macro("PTX73")
 #pragma pop_macro("PTX74")
+#pragma pop_macro("PTX75")

diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index ef2023cabf7f8..8c08ab3f5d749 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -33,9 +33,10 @@ enum class CudaVersion {
   CUDA_112,
   CUDA_113,
   CUDA_114,
-  FULLY_SUPPORTED = CUDA_114,
+  CUDA_115,
+  FULLY_SUPPORTED = CUDA_115,
   PARTIALLY_SUPPORTED =
-  CUDA_114, // Partially supported. Proceed with a warning.
+  CUDA_115, // Partially supported. Proceed with a warning.
   NEW = 1,  // Too new. Issue a warning, but allow using it.
 };
 const char *CudaVersionToString(CudaVersion V);

diff  --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index f5ee1fb4c2284..e82a3a705e70c 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -40,6 +40,8 @@ const char *CudaVersionToString(CudaVersion V) {
 return "11.3";
   case CudaVersion::CUDA_114:
 return "11.4";
+  case CudaVersion::CUDA_115:
+return "11.5";
   case CudaVersion::NEW:
 return "";
   }
@@ -62,6 +64,7 @@ CudaVersion CudaStringToVersion(const llvm::Twine &S) {
   .Case("11.2", CudaVersion::CUDA_112)
   .Case("11.3", CudaVersion::CUDA_113)
   .Case("11.4", CudaVersion::CUDA_114)
+  .Case("11.5", CudaVersion::CUDA_115)
   .Default(CudaVersion::UNKNOWN);
 }
 
@@ -241,6 +244,8 @@ CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
 return CudaVersion::CUDA_113;
   case 114:
 return CudaVersion::CUDA_114;
+  case 115:
+return CudaVersion::CUDA_115;
   default:
 return CudaVersion::UNKNOWN;
   }

diff  --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index 0461a91d0add7..3561b22677bc6 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -44,6 +44,7 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
 if (!Feature.startswith("+ptx"))
   continue;
 PTXVersion = llvm::StringSwitch(Feature)
+ .Case("+ptx75", 75)
  .Case("+ptx74", 74)
  .Case("+ptx73", 73)
  .Case("+ptx72", 72)

diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 09418aa2390f2..5397c7a9a0e66 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -65,6 +65,8 @@ CudaVersion getCudaVersion(uint32_t raw_version) {
 return CudaVersion::CUDA_113;
   if (raw_version < 11050)
 return CudaVersion::CUDA_114;
+  if (raw_version < 11060)
+return CudaVersion::CUDA_115;
   return CudaVersion::NEW;
 }
 
@@ -707,6 +709,7 @@ void CudaToolChain::addClangTargetOptions(
   case CudaVersion::CUDA_##CUDA_VER:   
\
 PtxFeature = "+ptx" #PTX_VER;  
\
 break;
+CASE_CUDA_VERSION(115, 75);
 CASE_CUDA_VERSION(114

[clang-tools-extra] c3e3c76 - [clang-tidy] Fix `bugprone-use-after-move` check to also consider moves in constructor initializers

2021-11-14 Thread Carlos Galvez via cfe-commits

Author: Fabian Wolff
Date: 2021-11-15T07:41:35Z
New Revision: c3e3c762098e8d425731bb40f3b8b04dac1013f3

URL: 
https://github.com/llvm/llvm-project/commit/c3e3c762098e8d425731bb40f3b8b04dac1013f3
DIFF: 
https://github.com/llvm/llvm-project/commit/c3e3c762098e8d425731bb40f3b8b04dac1013f3.diff

LOG: [clang-tidy] Fix `bugprone-use-after-move` check to also consider moves in 
constructor initializers

Fixes PR#38187. Constructors are actually already checked,
but only as functions, i.e. the check only looks at the
constructor body and not at the initializers, which misses
the (common) case where constructor parameters are moved
as part of an initializer expression.

One remaining false negative is when both the move //and//
the use-after-move occur in constructor initializers.
This is a lot more difficult to handle, though, because
the `bugprone-use-after-move` check is currently based on
a CFG that only takes the body into account, not the
initializers, so e.g. initialization order would have to
manually be considered. I will file a follow-up issue for
this once PR#38187 is closed.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D113708

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 136d8f862b956..064b6ae19784e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -129,8 +129,12 @@ bool UseAfterMoveFinder::find(Stmt *FunctionBody, const 
Expr *MovingCall,
   Visited.clear();
 
   const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall);
-  if (!Block)
-return false;
+  if (!Block) {
+// This can happen if MovingCall is in a constructor initializer, which is
+// not included in the CFG because the CFG is built only from the function
+// body.
+Block = &TheCFG->getEntry();
+  }
 
   return findInternal(Block, MovingCall, MovedVariable, TheUseAfterMove);
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
index 73ca59ccc91bf..e26db0f6793e0 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -1338,3 +1338,15 @@ void typeId() {
   Foo Other{std::move(Bar)};
 }
 } // namespace UnevalContext
+
+class PR38187 {
+public:
+  PR38187(std::string val) : val_(std::move(val)) {
+val.empty();
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'val' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:30: note: move occurred here
+  }
+
+private:
+  std::string val_;
+};



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


[clang-tools-extra] 9699c0f - [clang-tidy][NFC] Simplify ClangTidyStats

2021-11-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2021-11-16T07:36:05Z
New Revision: 9699c0fea3552f687f8357032199890633d58fe2

URL: 
https://github.com/llvm/llvm-project/commit/9699c0fea3552f687f8357032199890633d58fe2
DIFF: 
https://github.com/llvm/llvm-project/commit/9699c0fea3552f687f8357032199890633d58fe2.diff

LOG: [clang-tidy][NFC] Simplify ClangTidyStats

- Use NSDMI and remove constructor.

Differential Revision: https://reviews.llvm.org/D113847

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index f93deae64bb3..234455c5bea2 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -45,18 +45,13 @@ struct ClangTidyError : tooling::Diagnostic {
   std::vector EnabledDiagnosticAliases;
 };
 
-/// Contains displayed and ignored diagnostic counters for a ClangTidy
-/// run.
+/// Contains displayed and ignored diagnostic counters for a ClangTidy run.
 struct ClangTidyStats {
-  ClangTidyStats()
-  : ErrorsDisplayed(0), ErrorsIgnoredCheckFilter(0), 
ErrorsIgnoredNOLINT(0),
-ErrorsIgnoredNonUserCode(0), ErrorsIgnoredLineFilter(0) {}
-
-  unsigned ErrorsDisplayed;
-  unsigned ErrorsIgnoredCheckFilter;
-  unsigned ErrorsIgnoredNOLINT;
-  unsigned ErrorsIgnoredNonUserCode;
-  unsigned ErrorsIgnoredLineFilter;
+  unsigned ErrorsDisplayed = 0;
+  unsigned ErrorsIgnoredCheckFilter = 0;
+  unsigned ErrorsIgnoredNOLINT = 0;
+  unsigned ErrorsIgnoredNonUserCode = 0;
+  unsigned ErrorsIgnoredLineFilter = 0;
 
   unsigned errorsIgnored() const {
 return ErrorsIgnoredNOLINT + ErrorsIgnoredCheckFilter +



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


[clang-tools-extra] 5bbe501 - [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2021-11-30T07:31:17Z
New Revision: 5bbe50148f3b515c170be22209395b72890f5b8c

URL: 
https://github.com/llvm/llvm-project/commit/5bbe50148f3b515c170be22209395b72890f5b8c
DIFF: 
https://github.com/llvm/llvm-project/commit/5bbe50148f3b515c170be22209395b72890f5b8c.diff

LOG: [clang-tidy] Warn on functional C-style casts

The google-readability-casting check is meant to be on par
with cpplint's readability/casting check, according to the
documentation. However it currently does not diagnose
functional casts, like:

float x = 1.5F;
int y = int(x);

This is detected by cpplint, however, and the guidelines
are clear that such a cast is only allowed when the type
is a class type (constructor call):

> You may use cast formats like `T(x)` only when `T` is a class type.

Therefore, update the clang-tidy check to check this
case.

Differential Revision: https://reviews.llvm.org/D114427

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index a32603dc2cb0..82804a670959 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -31,6 +31,11 @@ void AvoidCStyleCastsCheck::registerMatchers(
   unless(isInTemplateInstantiation()))
   .bind("cast"),
   this);
+  Finder->addMatcher(
+  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
+unless(hasDescendant(initListExpr(
+  .bind("cast"),
+  this);
 }
 
 static bool needsConstCast(QualType SourceType, QualType DestType) {
@@ -55,8 +60,39 @@ static bool pointedUnqualifiedTypesAreEqual(QualType T1, 
QualType T2) {
   return T1.getUnqualifiedType() == T2.getUnqualifiedType();
 }
 
+static clang::CharSourceRange getReplaceRange(const ExplicitCastExpr *Expr) {
+  if (const auto *CastExpr = dyn_cast(Expr)) {
+return CharSourceRange::getCharRange(
+CastExpr->getLParenLoc(),
+CastExpr->getSubExprAsWritten()->getBeginLoc());
+  } else if (const auto *CastExpr = dyn_cast(Expr)) {
+return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
+ CastExpr->getLParenLoc());
+  } else
+llvm_unreachable("Unsupported CastExpr");
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const ExplicitCastExpr *Expr) {
+  SourceLocation BeginLoc;
+  SourceLocation EndLoc;
+
+  if (const auto *CastExpr = dyn_cast(Expr)) {
+BeginLoc = CastExpr->getLParenLoc().getLocWithOffset(1);
+EndLoc = CastExpr->getRParenLoc().getLocWithOffset(-1);
+  } else if (const auto *CastExpr = dyn_cast(Expr)) {
+BeginLoc = CastExpr->getBeginLoc();
+EndLoc = CastExpr->getLParenLoc().getLocWithOffset(-1);
+  } else
+llvm_unreachable("Unsupported CastExpr");
+
+  return Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
+  SM, LangOpts);
+}
+
 void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *CastExpr = Result.Nodes.getNodeAs("cast");
+  const auto *CastExpr = Result.Nodes.getNodeAs("cast");
 
   // Ignore casts in macros.
   if (CastExpr->getExprLoc().isMacroID())
@@ -80,8 +116,7 @@ void AvoidCStyleCastsCheck::check(const 
MatchFinder::MatchResult &Result) {
   const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
   const QualType DestType = DestTypeAsWritten.getCanonicalType();
 
-  auto ReplaceRange = CharSourceRange::getCharRange(
-  CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getBeginLoc());
+  CharSourceRange ReplaceRange = getReplaceRange(CastExpr);
 
   bool FnToFnCast =
   IsFunction(SourceTypeAsWritten) && IsFunction(DestTypeAsWritten);
@@ -124,18 +159,14 @@ void AvoidCStyleCastsCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   // Leave type spelling exactly as it was (unlike
   // getTypeAsWritten().getAsString() which would spell enum types 'enum X').
-  StringRef DestTypeString =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(
-   CastExpr->getLParenLoc().getLocWithOffset(1),
-   CastExpr->getRParenLoc().getLocWithOffset(-1)),
-   SM, getLangOpts());
+  StringRef DestTypeString = getDestTypeString(SM, getLangOpts(), CastExpr);
 
   auto Diag =
   diag(CastExpr->getBeginLoc(), "C-style casts are discouraged; use %0");
 
   auto ReplaceWithCast = [&](std::string CastText) {
 const Expr *SubExp

[clang-tools-extra] 946eb7a - [clang-tidy][NFC] Move CachedGlobList to GlobList.h

2021-12-04 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2021-12-04T08:50:49Z
New Revision: 946eb7a037d5f83ea9cdc99bac0f939ddd344e09

URL: 
https://github.com/llvm/llvm-project/commit/946eb7a037d5f83ea9cdc99bac0f939ddd344e09
DIFF: 
https://github.com/llvm/llvm-project/commit/946eb7a037d5f83ea9cdc99bac0f939ddd344e09.diff

LOG: [clang-tidy][NFC] Move CachedGlobList to GlobList.h

Currently it's hidden inside ClangTidyDiagnosticConsumer,
so it's hard to know it exists.

Given that there are multiple uses of globs in clang-tidy,
it makes sense to have these classes publicly available
for other use cases that might benefit from it.

Also, add unit test by converting the existing tests
for GlobList into typed tests.

Reviewed By: salman-javed-nz

Differential Revision: https://reviews.llvm.org/D113422

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/GlobList.cpp
clang-tools-extra/clang-tidy/GlobList.h
clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 66329328757bd..b09079b5e8ba4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -155,29 +155,6 @@ ClangTidyError::ClangTidyError(StringRef CheckName,
 : tooling::Diagnostic(CheckName, DiagLevel, BuildDirectory),
   IsWarningAsError(IsWarningAsError) {}
 
-class ClangTidyContext::CachedGlobList {
-public:
-  CachedGlobList(StringRef Globs) : Globs(Globs) {}
-
-  bool contains(StringRef S) {
-switch (auto &Result = Cache[S]) {
-case Yes:
-  return true;
-case No:
-  return false;
-case None:
-  Result = Globs.contains(S) ? Yes : No;
-  return Result == Yes;
-}
-llvm_unreachable("invalid enum");
-  }
-
-private:
-  GlobList Globs;
-  enum Tristate { None, Yes, No };
-  llvm::StringMap Cache;
-};
-
 ClangTidyContext::ClangTidyContext(
 std::unique_ptr OptionsProvider,
 bool AllowEnablingAnalyzerAlphaCheckers)

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 129c06f60f569..23800f5622f69 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -29,6 +29,7 @@ class CompilationDatabase;
 } // namespace tooling
 
 namespace tidy {
+class CachedGlobList;
 
 /// A detected error complete with information to display diagnostic and
 /// automatic fix.
@@ -191,7 +192,7 @@ class ClangTidyContext {
 
   std::string CurrentFile;
   ClangTidyOptions CurrentOptions;
-  class CachedGlobList;
+
   std::unique_ptr CheckFilter;
   std::unique_ptr WarningAsErrorFilter;
 

diff  --git a/clang-tools-extra/clang-tidy/GlobList.cpp 
b/clang-tools-extra/clang-tidy/GlobList.cpp
index ccdf856083759..b594d943cc075 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -9,8 +9,8 @@
 #include "GlobList.h"
 #include "llvm/ADT/SmallString.h"
 
-using namespace clang;
-using namespace tidy;
+namespace clang {
+namespace tidy {
 
 // Returns true if GlobList starts with the negative indicator ('-'), removes 
it
 // from the GlobList.
@@ -62,3 +62,19 @@ bool GlobList::contains(StringRef S) const {
   }
   return false;
 }
+
+bool CachedGlobList::contains(StringRef S) const {
+  switch (auto &Result = Cache[S]) {
+  case Yes:
+return true;
+  case No:
+return false;
+  case None:
+Result = GlobList::contains(S) ? Yes : No;
+return Result == Yes;
+  }
+  llvm_unreachable("invalid enum");
+}
+
+} // namespace tidy
+} // namespace clang

diff  --git a/clang-tools-extra/clang-tidy/GlobList.h 
b/clang-tools-extra/clang-tidy/GlobList.h
index 17730078b6f31..de7020ef3f165 100644
--- a/clang-tools-extra/clang-tidy/GlobList.h
+++ b/clang-tools-extra/clang-tidy/GlobList.h
@@ -11,6 +11,7 @@
 
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
 
@@ -24,6 +25,8 @@ namespace tidy {
 /// them in the order of appearance in the list.
 class GlobList {
 public:
+  virtual ~GlobList() = default;
+
   /// \p Globs is a comma-separated list of globs (only the '*' metacharacter 
is
   /// supported) with an optional '-' prefix to denote exclusion.
   ///
@@ -36,10 +39,9 @@ class GlobList {
 
   /// Returns \c true if the pattern matches \p S. The result is the last
   /// matching glob's Positive flag.
-  bool contains(StringRef S) const;
+  virtual bool contains(StringRef S) const;
 
 private:
-
   struct GlobListItem {
 bool IsPositive;
 llvm::Regex Regex;
@@ -4

[clang-tools-extra] 9ae5896 - [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-08-11 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-08-11T07:46:04Z
New Revision: 9ae5896d9673a54f4a6cf656624891bafc192857

URL: 
https://github.com/llvm/llvm-project/commit/9ae5896d9673a54f4a6cf656624891bafc192857
DIFF: 
https://github.com/llvm/llvm-project/commit/9ae5896d9673a54f4a6cf656624891bafc192857.diff

LOG: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

Flags uses of const-qualified and reference data members in structs.
Implements rule C.12 of C++ Core Guidelines.

Differential Revision: https://reviews.llvm.org/D126880

Added: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
new file mode 100644
index 0..5f340736c8dde
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
@@ -0,0 +1,38 @@
+//===--- AvoidConstOrRefDataMembersCheck.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 "AvoidConstOrRefDataMembersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+void AvoidConstOrRefDataMembersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  fieldDecl(hasType(hasCanonicalType(referenceType(.bind("ref"), this);
+  Finder->addMatcher(
+  fieldDecl(hasType(qualType(isConstQualified(.bind("const"), this);
+}
+
+void AvoidConstOrRefDataMembersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("ref"))
+diag(MatchedDecl->getLocation(), "member %0 of type %1 is a reference")
+<< MatchedDecl << MatchedDecl->getType();
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("const"))
+diag(MatchedDecl->getLocation(), "member %0 of type %1 is const qualified")
+<< MatchedDecl << MatchedDecl->getType();
+}
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
new file mode 100644
index 0..7fd94aa7daa26
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
@@ -0,0 +1,38 @@
+//===--- AvoidConstOrRefDataMembersCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCONSTORREFDATAMEMBERSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCONSTORREFDATAMEMBERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Const-qualified or reference data members in classes should be avoided, as
+/// they make the class non-copy-assignable.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.html
+class AvoidConstOrRefDataMembersCheck : public ClangTidyCheck {
+public:
+  AvoidConstOrRefDataMembersCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus;
+  }
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // 

[clang-tools-extra] 3fd4213 - [clang-tidy] Do not trigger cppcoreguidelines-avoid-const-or-ref-data-members on lambda captures

2022-08-19 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-08-19T08:26:34Z
New Revision: 3fd4213059a4ea9453809aeccd1bfc7d115d24b2

URL: 
https://github.com/llvm/llvm-project/commit/3fd4213059a4ea9453809aeccd1bfc7d115d24b2
DIFF: 
https://github.com/llvm/llvm-project/commit/3fd4213059a4ea9453809aeccd1bfc7d115d24b2.diff

LOG: [clang-tidy] Do not trigger 
cppcoreguidelines-avoid-const-or-ref-data-members on lambda captures

Lambdas are implemented as regular classes internally,
and the captured variables end up as members there.
Do not diagnose those - the check should cover only
regular classes and structs.

Differential Revision: https://reviews.llvm.org/D131780

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
index 5f340736c8dde..aa530ff9e098c 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
@@ -15,12 +15,23 @@ using namespace clang::ast_matchers;
 namespace clang {
 namespace tidy {
 namespace cppcoreguidelines {
+namespace {
+
+AST_MATCHER(FieldDecl, isMemberOfLambda) {
+  return Node.getParent()->isLambda();
+}
+
+} // namespace
 
 void AvoidConstOrRefDataMembersCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  fieldDecl(hasType(hasCanonicalType(referenceType(.bind("ref"), this);
-  Finder->addMatcher(
-  fieldDecl(hasType(qualType(isConstQualified(.bind("const"), this);
+  Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
+   hasType(hasCanonicalType(referenceType(
+ .bind("ref"),
+ this);
+  Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
+   hasType(qualType(isConstQualified(
+ .bind("const"),
+ this);
 }
 
 void AvoidConstOrRefDataMembersCheck::check(

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
index 01aed9dfdc1e2..becc3ee8ba9d8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
@@ -167,3 +167,41 @@ TemplatedConst t2{123};
 TemplatedConstRef t3{123};
 TemplatedRefRef t4{123};
 TemplatedRef t5{t1.t};
+
+// Lambdas capturing const or ref members should not trigger warnings
+void lambdas()
+{
+  int x1{123};
+  const int x2{123};
+  const int& x3{123};
+  int&& x4{123};
+  int& x5{x1};
+
+  auto v1 = [x1]{};
+  auto v2 = [x2]{};
+  auto v3 = [x3]{};
+  auto v4 = [x4]{};
+  auto v5 = [x5]{};
+
+  auto r1 = [&x1]{};
+  auto r2 = [&x2]{};
+  auto r3 = [&x3]{};
+  auto r4 = [&x4]{};
+  auto r5 = [&x5]{};
+
+  auto iv = [=]{
+auto c1 = x1;
+auto c2 = x2;
+auto c3 = x3;
+auto c4 = x4;
+auto c5 = x5;
+  };
+
+  auto ir = [&]{
+auto c1 = x1;
+auto c2 = x2;
+auto c3 = x3;
+auto c4 = x4;
+auto c5 = x5;
+  };
+}



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


[clang-tools-extra] 1ae33bf - [clang-tidy] Add cppcoreguidelines-avoid-do-while check

2022-10-10 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-10-10T07:29:17Z
New Revision: 1ae33bf42680b156fe0f5cd6163bf24ef45d8cd3

URL: 
https://github.com/llvm/llvm-project/commit/1ae33bf42680b156fe0f5cd6163bf24ef45d8cd3
DIFF: 
https://github.com/llvm/llvm-project/commit/1ae33bf42680b156fe0f5cd6163bf24ef45d8cd3.diff

LOG: [clang-tidy] Add cppcoreguidelines-avoid-do-while check

Implements rule ES.75 of C++ Core Guidelines.

Differential Revision: https://reviews.llvm.org/D132461

Added: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-do-while.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.cpp
new file mode 100644
index 0..1746b98714946
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.cpp
@@ -0,0 +1,41 @@
+//===--- AvoidDoWhileCheck.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 "AvoidDoWhileCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+AvoidDoWhileCheck::AvoidDoWhileCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", false)) {}
+
+void AvoidDoWhileCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+}
+
+void AvoidDoWhileCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(doStmt().bind("x"), this);
+}
+
+void AvoidDoWhileCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("x")) {
+if (IgnoreMacros && MatchedDecl->getBeginLoc().isMacroID())
+  return;
+diag(MatchedDecl->getBeginLoc(), "avoid do-while loops");
+  }
+}
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.h
new file mode 100644
index 0..757842bf525bf
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.h
@@ -0,0 +1,41 @@
+//===--- AvoidDoWhileCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDDOWHILECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDDOWHILECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// do-while loops are less readable than plan while loops, and can lead to
+/// subtle bugs.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-do-while.html
+class AvoidDoWhileCheck : public ClangTidyCheck {
+public:
+  AvoidDoWhileCheck(StringRef Name, ClangTidyContext *Context);
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus;
+  }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  bool IgnoreMacros;
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDDOWHILECHECK_H

diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index 832b0bf9d9e5e..6fb11858e44a1 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-too

[clang-tools-extra] bf452f9 - [clang-tidy][NFC] Replace custom isStatic matcher with the existing isStaticStorageClass

2022-12-19 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-12-19T15:23:50Z
New Revision: bf452f9b347aa0e1f8f368da925b8e1ca27df0c5

URL: 
https://github.com/llvm/llvm-project/commit/bf452f9b347aa0e1f8f368da925b8e1ca27df0c5
DIFF: 
https://github.com/llvm/llvm-project/commit/bf452f9b347aa0e1f8f368da925b8e1ca27df0c5.diff

LOG: [clang-tidy][NFC] Replace custom isStatic matcher with the existing 
isStaticStorageClass

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
index b26632d10779..211bd3c73e12 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -16,11 +16,6 @@ namespace clang {
 namespace tidy {
 namespace misc {
 namespace {
-AST_POLYMORPHIC_MATCHER(isStatic, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
-  VarDecl)) {
-  return Node.getStorageClass() == SC_Static;
-}
-
 AST_POLYMORPHIC_MATCHER_P(isInHeaderFile,
   AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
   VarDecl),
@@ -60,13 +55,13 @@ void UseAnonymousNamespaceCheck::storeOptions(
 
 void UseAnonymousNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isStatic(),
+  functionDecl(isStaticStorageClass(),
unless(anyOf(isInHeaderFile(HeaderFileExtensions),
 isInAnonymousNamespace(), isMemberFunction(
   .bind("x"),
   this);
   Finder->addMatcher(
-  varDecl(isStatic(),
+  varDecl(isStaticStorageClass(),
   unless(anyOf(isInHeaderFile(HeaderFileExtensions),
isInAnonymousNamespace(), isStaticLocal(),
isStaticDataMember(), hasType(isConstQualified()



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


[clang] 125ccd3 - [ASTMatchers] Add isInAnonymousNamespace narrowing matcher

2022-12-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-12-23T07:39:03Z
New Revision: 125ccd3751472a0c709498f83671577ffed394a6

URL: 
https://github.com/llvm/llvm-project/commit/125ccd3751472a0c709498f83671577ffed394a6
DIFF: 
https://github.com/llvm/llvm-project/commit/125ccd3751472a0c709498f83671577ffed394a6.diff

LOG: [ASTMatchers] Add isInAnonymousNamespace narrowing matcher

Used in a couple clang-tidy checks so it could be extracted
out as its own matcher.

Differential Revision: https://reviews.llvm.org/D140328

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 61844ffc9de90..f9cb9f2e942bb 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3962,6 +3962,25 @@ Narrowing Matchers
 cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
 
 
+MatcherDecl>isInAnonymousNamespace
+Matches 
declarations in an anonymous namespace.
+
+Given
+  class vector {};
+  namespace foo {
+class vector {};
+namespace {
+  class vector {}; // #1
+}
+  }
+  namespace {
+class vector {}; // #2
+namespace foo {
+  class vector{}; // #3
+}
+  }
+cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match #1, #2 
and #3.
+
 
 MatcherDecl>isInstantiated
 Matches declarations 
that are template instantiations or are inside

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c288a98eec99..48ffafafb1bb7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -859,6 +859,7 @@ Build System Changes
 
 AST Matchers
 
+- Add ``isInAnoymousNamespace`` matcher to match declarations in an anonymous 
namespace.
 
 clang-format
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index dfea432c16adb..5d3d458b6409f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7813,6 +7813,30 @@ AST_MATCHER(NamespaceDecl, isAnonymous) {
 /// cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
 AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); }
 
+/// Matches declarations in an anonymous namespace.
+///
+/// Given
+/// \code
+///   class vector {};
+///   namespace foo {
+/// class vector {};
+/// namespace {
+///   class vector {}; // #1
+/// }
+///   }
+///   namespace {
+/// class vector {}; // #2
+/// namespace foo {
+///   class vector{}; // #3
+/// }
+///   }
+/// \endcode
+/// cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match
+/// #1, #2 and #3.
+AST_MATCHER(Decl, isInAnonymousNamespace) {
+  return Node.isInAnonymousNamespace();
+}
+
 /// If the given case statement does not use the GNU case range
 /// extension, matches the constant given in the statement.
 ///

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 752a736ae800e..2c8b67f2644fd 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3550,6 +3550,41 @@ TEST_P(ASTMatchersTest, InStdNamespace) {
   cxxRecordDecl(hasName("vector"), isInStdNamespace(;
 }
 
+TEST_P(ASTMatchersTest, InAnonymousNamespace) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+
+  EXPECT_TRUE(
+  notMatches("class vector {};"
+ "namespace foo {"
+ "  class vector {};"
+ "}",
+ cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace {"
+  "  class vector {};"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace foo {"
+  "  namespace {"
+  "class vector {};"
+  "  }"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace {"
+  "  namespace foo {"
+  "class vector {};"
+  "  }"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+}
+
 TEST_P(ASTMatchersTest, InStdNamespace_CXX11) {
   if (!GetParam().isCXX11OrLater()) {
 return;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.or

[clang-tools-extra] e82dd5b - [clang-tidy][NFC] Remove custom isInAnonymousNamespace matchers

2022-12-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-12-23T08:54:48Z
New Revision: e82dd5b37c7d6ccd67c5118fe7400c6006e67d73

URL: 
https://github.com/llvm/llvm-project/commit/e82dd5b37c7d6ccd67c5118fe7400c6006e67d73
DIFF: 
https://github.com/llvm/llvm-project/commit/e82dd5b37c7d6ccd67c5118fe7400c6006e67d73.diff

LOG: [clang-tidy][NFC] Remove custom isInAnonymousNamespace matchers

Since now the same matcher exists in ASTMatchers.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp

clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
index 211bd3c73e12e..909bf793a9197 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -29,10 +29,6 @@ AST_MATCHER(FunctionDecl, isMemberFunction) {
   return llvm::isa(&Node);
 }
 AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
-
-AST_MATCHER(Decl, isInAnonymousNamespace) {
-  return Node.isInAnonymousNamespace();
-}
 } // namespace
 
 UseAnonymousNamespaceCheck::UseAnonymousNamespaceCheck(

diff  --git 
a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
index b76c1837b8019..ffd1238e421c3 100644
--- 
a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
@@ -17,10 +17,6 @@ namespace clang {
 namespace tidy {
 namespace readability {
 
-AST_MATCHER(NamedDecl, isInAnonymousNamespace) {
-  return Node.isInAnonymousNamespace();
-}
-
 void StaticDefinitionInAnonymousNamespaceCheck::registerMatchers(
 MatchFinder *Finder) {
   Finder->addMatcher(



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


[clang-tools-extra] b06b248 - [clang-tidy] Implement CppCoreGuideline CP.53

2023-01-05 Thread Carlos Galvez via cfe-commits

Author: Chris Cotter
Date: 2023-01-05T13:57:22Z
New Revision: b06b248ad9dc1b50dcf474616c3d586d47270a01

URL: 
https://github.com/llvm/llvm-project/commit/b06b248ad9dc1b50dcf474616c3d586d47270a01
DIFF: 
https://github.com/llvm/llvm-project/commit/b06b248ad9dc1b50dcf474616c3d586d47270a01.diff

LOG: [clang-tidy] Implement CppCoreGuideline CP.53

Implement CppCoreGuideline CP.53 to warn when a coroutine accepts
references parameters. Although the guideline mentions that it is safe
to access a reference parameter before suspension points, the guideline
recommends flagging all coroutine parameter references.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140793

Added: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
new file mode 100644
index 0..018aaad9a8d7a
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
@@ -0,0 +1,38 @@
+//===--- AvoidReferenceCoroutineParametersCheck.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 "AvoidReferenceCoroutineParametersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+void AvoidReferenceCoroutineParametersCheck::registerMatchers(
+MatchFinder *Finder) {
+  auto IsCoroMatcher =
+  hasDescendant(expr(anyOf(coyieldExpr(), coreturnStmt(), coawaitExpr(;
+  Finder->addMatcher(parmVarDecl(hasType(type(referenceType())),
+ hasAncestor(functionDecl(IsCoroMatcher)))
+ .bind("param"),
+ this);
+}
+
+void AvoidReferenceCoroutineParametersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  if (const auto *Param = Result.Nodes.getNodeAs("param")) {
+diag(Param->getBeginLoc(), "coroutine parameters should not be 
references");
+  }
+}
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
new file mode 100644
index 0..502b5717893b3
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
@@ -0,0 +1,40 @@
+//===--- AvoidReferenceCoroutineParametersCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDREFERENCECOROUTINEPARAMETERSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDREFERENCECOROUTINEPARAMETERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Warns on coroutines that accept reference parameters. Accessing a reference
+/// after a coroutine suspension point is not safe since the reference may no
+/// longer be valid. This implements CppCoreGuideline CP.53.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.html
+class AvoidReferenceCoroutineParametersCheck : public ClangTidyCheck {
+public:
+  AvoidReferenceCoroutineParametersCheck(StringRef Name,
+ ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  vo

[clang-tools-extra] 210b731 - [clang-tidy] Fix minor bug in add_new_check.py

2023-01-05 Thread Carlos Galvez via cfe-commits

Author: Chris Cotter
Date: 2023-01-05T15:28:57Z
New Revision: 210b731c01b020693aa8f53231c659ff5f60149e

URL: 
https://github.com/llvm/llvm-project/commit/210b731c01b020693aa8f53231c659ff5f60149e
DIFF: 
https://github.com/llvm/llvm-project/commit/210b731c01b020693aa8f53231c659ff5f60149e.diff

LOG: [clang-tidy] Fix minor bug in add_new_check.py

While rebuilding the list of checks in add_new_check.py,
check is a file is a subdirectory before traversing it.

Test plan: Ran `./add_new_check.py --update-docs` and confirmed the list.rst 
file was unchanged.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140772

Added: 


Modified: 
clang-tools-extra/clang-tidy/add_new_check.py
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index a85767acdce91..e3ad7a286a444 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -322,8 +322,7 @@ def update_checks_list(clang_tidy_path):
 lines = f.readlines()
   # Get all existing docs
   doc_files = []
-  for subdir in list(filter(lambda s: not s.endswith('.rst') and not 
s.endswith('.py'),
- os.listdir(docs_dir))):
+  for subdir in filter(lambda s: os.path.isdir(os.path.join(docs_dir, s)), 
os.listdir(docs_dir)):
 for file in filter(lambda s: s.endswith('.rst'), 
os.listdir(os.path.join(docs_dir, subdir))):
   doc_files.append([subdir, file])
   doc_files.sort()

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 989f4b52d4ac8..0f060f7f5fc7b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -99,6 +99,9 @@ Improvements to clang-tidy
 - Change to Python 3 in the shebang of `add_new_check.py` and 
`rename_check.py`,
   as the existing code is not compatible with Python 2.
 
+- Fix a minor bug in `add_new_check.py` to only traverse subdirectories
+  when updating the list of checks in the documentation.
+
 New checks
 ^^
 



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


[clang-tools-extra] c0d0b12 - [clang-tidy][NFC] Remove unused User argument in misc-misleading-bidirectional check

2023-01-08 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-01-08T15:18:13Z
New Revision: c0d0b1237a9f9ee992f6775305113738e9374ca0

URL: 
https://github.com/llvm/llvm-project/commit/c0d0b1237a9f9ee992f6775305113738e9374ca0
DIFF: 
https://github.com/llvm/llvm-project/commit/c0d0b1237a9f9ee992f6775305113738e9374ca0.diff

LOG: [clang-tidy][NFC] Remove unused User argument in 
misc-misleading-bidirectional check

It's not used anywhere.

Differential Revision: https://reviews.llvm.org/D141118

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp 
b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
index 3706f43d255b..dad6737ab40c 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -90,8 +90,7 @@ static bool containsMisleadingBidi(StringRef Buffer,
 class MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
 : public CommentHandler {
 public:
-  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck &Check,
- std::optional User)
+  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck &Check)
   : Check(Check) {}
 
   bool HandleComment(Preprocessor &PP, SourceRange Range) override {
@@ -114,8 +113,7 @@ class 
MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
 MisleadingBidirectionalCheck::MisleadingBidirectionalCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  Handler(std::make_unique(
-  *this, Context->getOptions().User)) {}
+  Handler(std::make_unique(*this)) {}
 
 MisleadingBidirectionalCheck::~MisleadingBidirectionalCheck() = default;
 



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


[clang-tools-extra] e432952 - [clang-tidy] Match derived types in in modernize-loop-convert

2023-01-10 Thread Carlos Galvez via cfe-commits

Author: Chris Cotter
Date: 2023-01-10T16:08:25Z
New Revision: e43295209bb86e93008363c66c1277c7d8bb148c

URL: 
https://github.com/llvm/llvm-project/commit/e43295209bb86e93008363c66c1277c7d8bb148c
DIFF: 
https://github.com/llvm/llvm-project/commit/e43295209bb86e93008363c66c1277c7d8bb148c.diff

LOG: [clang-tidy] Match derived types in in modernize-loop-convert

This patch allows clang-tidy to replace traditional for-loops where the
container type inherits its `begin`/`end` methods from a base class.

Test plan: Added unit test cases that confirm the tool replaces the new
pattern.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140307

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 84df6445ef77e..0056acbe5fc8a 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -252,17 +252,18 @@ StatementMatcher makePseudoArrayLoopMatcher() {
   // functions called begin() and end() taking the container as an argument
   // are also allowed.
   TypeMatcher RecordWithBeginEnd = qualType(anyOf(
-  qualType(
-  isConstQualified(),
-  hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
-  hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
-  hasMethod(cxxMethodDecl(hasName("end"),
-  isConst()   // hasDeclaration
- ))), // qualType
+  qualType(isConstQualified(),
+   hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+   cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
+   hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
+   hasMethod(cxxMethodDecl(hasName("end"),
+   isConst())) // 
hasDeclaration
+  ))), // qualType
   qualType(unless(isConstQualified()),
hasUnqualifiedDesugaredType(recordType(hasDeclaration(
-   cxxRecordDecl(hasMethod(hasName("begin")),
- hasMethod(hasName("end"))) // qualType
+   cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
+   hasMethod(hasName("begin")),
+   hasMethod(hasName("end") // qualType
   ));
 
   StatementMatcher SizeCallMatcher = cxxMemberCallExpr(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0f060f7f5fc7b..70d26dbe42d67 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -216,6 +216,10 @@ Changes in existing checks
   :doc: `readability-redundant-string-cstr 
`
   check.
 
+- Improved :doc:`modernize-loop-convert 
`
+  to check for container functions ``begin``/``end`` etc on base classes of 
the container
+  type, instead of only as direct members of the container type itself.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
index abd64904ee702..bc025ceab1f7a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -126,6 +126,10 @@ class dependent {
   void constFoo() const;
 };
 
+template
+class dependent_derived : public dependent {
+};
+
 template
 class doublyDependent{
  public:

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index b42ce4a19a6b7..96b3956358787 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -575,6 +575,7 @@ const dependent Constv;
 const dependent *Pconstv;
 
 transparent> Cv;
+dependent_derived VD;
 
 void f() {
   int Sum = 0;
@@ -653,6 +654,15 @@ void f() {
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = VD.size(); E != I; ++I) {
+printf("Fibonacci number is %d\n", VD[I]);
+Sum += VD[I] + 2;
+  }
+  //

[clang-tools-extra] 9fff1dd - [NFC] [clang-tools-extra] Alphabetize clang-tidy release notes

2023-01-10 Thread Carlos Galvez via cfe-commits

Author: Chris Cotter
Date: 2023-01-10T17:37:19Z
New Revision: 9fff1ddb560cbb14ba661af2c33b768f3071be9a

URL: 
https://github.com/llvm/llvm-project/commit/9fff1ddb560cbb14ba661af2c33b768f3071be9a
DIFF: 
https://github.com/llvm/llvm-project/commit/9fff1ddb560cbb14ba661af2c33b768f3071be9a.diff

LOG: [NFC] [clang-tools-extra] Alphabetize clang-tidy release notes

Alphabetize order of clang-tidy release notes, and fix `:doc:` link.

Reviewed By: Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D141391

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 70d26dbe42d67..a9fcc5a208bd8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -167,6 +167,16 @@ Changes in existing checks
   ` check for 
exceptions
   thrown by code emitted from macros in system headers.
 
+- Improved :doc:`misc-redundant-expression 
`
+  check.
+
+  The check now skips concept definitions since redundant expressions still 
make sense
+  inside them.
+
+- Improved :doc:`modernize-loop-convert 
`
+  to check for container functions ``begin``/``end`` etc on base classes of 
the container
+  type, instead of only as direct members of the container type itself.
+
 - Improved :doc:`modernize-use-emplace 
`
   check.
 
@@ -206,20 +216,10 @@ Changes in existing checks
   ` to not
   warn about `const` value parameters of declarations inside macros.
 
-- Improved :doc:`misc-redundant-expression 
`
-  check.
-
-  The check now skips concept definitions since redundant expressions still 
make sense
-  inside them.
-
 - Support removing ``c_str`` calls from ``std::string_view`` constructor calls 
in
-  :doc: `readability-redundant-string-cstr 
`
+  :doc:`readability-redundant-string-cstr 
`
   check.
 
-- Improved :doc:`modernize-loop-convert 
`
-  to check for container functions ``begin``/``end`` etc on base classes of 
the container
-  type, instead of only as direct members of the container type itself.
-
 Removed checks
 ^^
 



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


[clang-tools-extra] c7575fc - Revert "[clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options"

2023-01-24 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-01-25T05:17:00Z
New Revision: c7575fcb685a15f5384c137c76913e0bb11d1320

URL: 
https://github.com/llvm/llvm-project/commit/c7575fcb685a15f5384c137c76913e0bb11d1320
DIFF: 
https://github.com/llvm/llvm-project/commit/c7575fcb685a15f5384c137c76913e0bb11d1320.diff

LOG: Revert "[clang-tidy] Introduce HeaderFileExtensions and 
ImplementationFileExtensions options"

This reverts commit 4240c9146248ac0a91c45dee421c6ef07709ba74.

The current solution won't work since getLocalOrGlobal does not
support returning a vector. More work needs to be put into
ensuring both the local and global way of setting the options
are available during the transition period.

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.h
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
clang-tools-extra/docs/clang-tidy/index.rst
clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 84defccde513e..808929b11f796 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -122,9 +122,6 @@ template <> struct MappingTraits {
 bool Ignored = false;
 IO.mapOptional("Checks", Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
-IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
-IO.mapOptional("ImplementationFileExtensions",
-   Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
 IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
@@ -145,8 +142,6 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
   ClangTidyOptions Options;
   Options.Checks = "";
   Options.WarningsAsErrors = "";
-  Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
-  Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
   Options.HeaderFilterRegex = "";
   Options.SystemHeaders = false;
   Options.FormatStyle = "none";
@@ -183,9 +178,6 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const 
ClangTidyOptions &Other,
   unsigned Order) {
   mergeCommaSeparatedLists(Checks, Other.Checks);
   mergeCommaSeparatedLists(WarningsAsErrors, Other.WarningsAsErrors);
-  overrideValue(HeaderFileExtensions, Other.HeaderFileExtensions);
-  overrideValue(ImplementationFileExtensions,
-Other.ImplementationFileExtensions);
   overrideValue(HeaderFilterRegex, Other.HeaderFilterRegex);
   overrideValue(SystemHeaders, Other.SystemHeaders);
   overrideValue(FormatStyle, Other.FormatStyle);

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index d0df474bc38e0..4a6cdf097905b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -71,14 +71,6 @@ struct ClangTidyOptions {
   /// WarningsAsErrors filter.
   std::optional WarningsAsErrors;
 
-  /// File extensions to consider to determine if a given diagnostic is located
-  /// in a header file.
-  std::optional> HeaderFileExtensions;
-
-  /// File extensions to consider to determine if a given diagnostic is located
-  /// is located in an implementation file.
-  std::optional> ImplementationFileExtensions;
-
   /// Output warnings from headers matching this filter. Warnings from
   /// main files will always be displayed.
   std::optional HeaderFilterRegex;

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index e8728c046e334..765b8483561ea 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -46,14 +46,12 @@ Configuration files:
 
 $ clang-tidy -dump-config
 ---
-Checks:   '-*,some-check'
-WarningsAsErrors: ''
-HeaderFileExtensions: ['', 'h','hh','hpp','hxx']
-ImplementationFileExtensions: ['c

[clang-tools-extra] 8a8f77c - [clang-tidy] Implement CppCoreGuideline F.54

2023-02-01 Thread Carlos Galvez via cfe-commits

Author: Chris Cotter
Date: 2023-02-02T07:20:59Z
New Revision: 8a8f77c1b849ff59ef0db457bd74f4adb1de7cfa

URL: 
https://github.com/llvm/llvm-project/commit/8a8f77c1b849ff59ef0db457bd74f4adb1de7cfa
DIFF: 
https://github.com/llvm/llvm-project/commit/8a8f77c1b849ff59ef0db457bd74f4adb1de7cfa.diff

LOG: [clang-tidy] Implement CppCoreGuideline F.54

Warn when a lambda specifies a default capture and captures
``this``. Offer FixIts to correct the code.

Reviewed By: njames93, carlosgalvezp

Differential Revision: https://reviews.llvm.org/D141133

Added: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
new file mode 100644
index 0..11ef35178765f
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
@@ -0,0 +1,98 @@
+//===--- AvoidCaptureDefaultWhenCapturingThisCheck.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 "AvoidCaptureDefaultWhenCapturingThisCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+void AvoidCaptureDefaultWhenCapturingThisCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(lambdaExpr(hasAnyCapture(capturesThis())).bind("lambda"),
+ this);
+}
+
+static SourceLocation findDefaultCaptureEnd(const LambdaExpr *Lambda,
+ASTContext &Context) {
+  for (const LambdaCapture &Capture : Lambda->explicit_captures()) {
+if (Capture.isExplicit()) {
+  if (Capture.getCaptureKind() == LCK_ByRef) {
+const SourceManager &SourceMgr = Context.getSourceManager();
+SourceLocation AddressofLoc = utils::lexer::findPreviousTokenKind(
+Capture.getLocation(), SourceMgr, Context.getLangOpts(), tok::amp);
+return AddressofLoc;
+  } else {
+return Capture.getLocation();
+  }
+}
+  }
+  return Lambda->getIntroducerRange().getEnd();
+}
+
+static std::string createReplacementText(const LambdaExpr *Lambda) {
+  std::string Replacement;
+  llvm::raw_string_ostream Stream(Replacement);
+
+  auto AppendName = [&](llvm::StringRef Name) {
+if (Replacement.size() != 0) {
+  Stream << ", ";
+}
+if (Lambda->getCaptureDefault() == LCD_ByRef && Name != "this") {
+  Stream << "&" << Name;
+} else {
+  Stream << Name;
+}
+  };
+
+  for (const LambdaCapture &Capture : Lambda->implicit_captures()) {
+assert(Capture.isImplicit());
+if (Capture.capturesVariable() && Capture.isImplicit()) {
+  AppendName(Capture.getCapturedVar()->getName());
+} else if (Capture.capturesThis()) {
+  AppendName("this");
+}
+  }
+  if (Replacement.size() &&
+  Lambda->explicit_capture_begin() != Lambda->explicit_capture_end()) {
+// Add back separator if we are adding explicit capture variables.
+Stream << ", ";
+  }
+  return Replacement;
+}
+
+void AvoidCaptureDefaultWhenCapturingThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+  if (const auto *Lambda = Result.Nodes.getNodeAs("lambda")) {
+if (Lambda->getCaptureDefault() != LCD_None) {
+  bool IsThisImplicitlyCaptured = std::any_of(
+  Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
+  [](const LambdaCapture &Capture) { return Capture.capturesThis(); });
+  auto Diag = diag(Lambda->getCaptureDefaultLoc(),
+   "lambdas that %select{|implicitly }0capture 'this' "
+   "should not specify a capture default")
+  << IsThisImplicitlyCaptured;
+
+  std::string ReplacementText = createReplacementText(Lambda);

[clang-tools-extra] 0f5eb31 - [clang-tidy][doc] Deprecate the AnalyzeTemporaryDtors option

2023-01-12 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-01-13T07:29:49Z
New Revision: 0f5eb3190cfc09796b08648fac7e936ffdcfb8d7

URL: 
https://github.com/llvm/llvm-project/commit/0f5eb3190cfc09796b08648fac7e936ffdcfb8d7
DIFF: 
https://github.com/llvm/llvm-project/commit/0f5eb3190cfc09796b08648fac7e936ffdcfb8d7.diff

LOG: [clang-tidy][doc] Deprecate the AnalyzeTemporaryDtors option

It's not used anywhere, and we should not keep it
for eternity. Document it as deprecated and announce
its removal 2 releases later, so people have time
to update their .clang-tidy files.

Differential Revision: https://reviews.llvm.org/D141583

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 43001a37f2f8a..7d26e34192b61 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -124,7 +124,7 @@ template <> struct MappingTraits {
 IO.mapOptional("Checks", Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
-IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // legacy compatibility
+IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a9fcc5a208bd8..434dcd955679d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,6 +102,10 @@ Improvements to clang-tidy
 - Fix a minor bug in `add_new_check.py` to only traverse subdirectories
   when updating the list of checks in the documentation.
 
+- Deprecate the global configuration file option `AnalyzeTemporaryDtors`,
+  which is no longer in use. The option will be fully removed in
+  :program:`clang-tidy` version 18.
+
 New checks
 ^^
 



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


[clang-tools-extra] 4240c91 - [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-01-23T20:58:34Z
New Revision: 4240c9146248ac0a91c45dee421c6ef07709ba74

URL: 
https://github.com/llvm/llvm-project/commit/4240c9146248ac0a91c45dee421c6ef07709ba74
DIFF: 
https://github.com/llvm/llvm-project/commit/4240c9146248ac0a91c45dee421c6ef07709ba74.diff

LOG: [clang-tidy] Introduce HeaderFileExtensions and 
ImplementationFileExtensions options

We have a number of checks designed to analyze problems
in header files only, for example:

bugprone-suspicious-include
google-build-namespaces
llvm-header-guard
misc-definitions-in-header
...

All these checks duplicate the same logic and options
to determine whether a location is placed in the main
source file or in the header. More checks are coming
up with similar requirements.

Thus, to remove duplication, let's move this option
to the top-level configuration of clang-tidy (since
it's something all checks should share).

Since the checks fetch the option via getLocalOrGlobal,
the behavior is unchanged.

Add a deprecation notice for all checks that use the
local option, prompting to update to the global option.

The functionality for parsing the option will need to
remain in the checks during the transition period.
Once the local options are fully removed, the goal
is to store the parsed options in the ClangTidyContext,
that checks can easily have access to.

Differential Revision: https://reviews.llvm.org/D141000

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.h
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
clang-tools-extra/docs/clang-tidy/index.rst
clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 808929b11f796..84defccde513e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -122,6 +122,9 @@ template <> struct MappingTraits {
 bool Ignored = false;
 IO.mapOptional("Checks", Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
+IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
+IO.mapOptional("ImplementationFileExtensions",
+   Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
 IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
@@ -142,6 +145,8 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
   ClangTidyOptions Options;
   Options.Checks = "";
   Options.WarningsAsErrors = "";
+  Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
+  Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
   Options.HeaderFilterRegex = "";
   Options.SystemHeaders = false;
   Options.FormatStyle = "none";
@@ -178,6 +183,9 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const 
ClangTidyOptions &Other,
   unsigned Order) {
   mergeCommaSeparatedLists(Checks, Other.Checks);
   mergeCommaSeparatedLists(WarningsAsErrors, Other.WarningsAsErrors);
+  overrideValue(HeaderFileExtensions, Other.HeaderFileExtensions);
+  overrideValue(ImplementationFileExtensions,
+Other.ImplementationFileExtensions);
   overrideValue(HeaderFilterRegex, Other.HeaderFilterRegex);
   overrideValue(SystemHeaders, Other.SystemHeaders);
   overrideValue(FormatStyle, Other.FormatStyle);

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 727c55c3e..927371558d3bc 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -72,6 +72,14 @@ struct ClangTidyOptions {
   /// WarningsAsErrors filter.
   std::optional WarningsAsErrors;
 
+  /// File extensions to consider to determine if a given diagnostic is located
+  /// in a header file.
+  std::optional> HeaderFileExtensions;
+
+  /// File extensions to consider to determine if a given diagnostic is located
+  /// is located in an implementation file.
+  std::optional> Imp

[clang-tools-extra] 38a9e1d - [clang-tidy][NFC] Fix Release Notes build error

2023-01-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-01-23T21:05:08Z
New Revision: 38a9e1d41264b551f659a5d9215109a96e74cadd

URL: 
https://github.com/llvm/llvm-project/commit/38a9e1d41264b551f659a5d9215109a96e74cadd
DIFF: 
https://github.com/llvm/llvm-project/commit/38a9e1d41264b551f659a5d9215109a96e74cadd.diff

LOG: [clang-tidy][NFC] Fix Release Notes build error

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 164fe12b9e610..c83306f67b415 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -213,7 +213,7 @@ Changes in existing checks
 
 - Deprecated check-local options `HeaderFileExtensions` and 
`ImplementationFileExtensions`
   in :doc:`misc-unused-using-decls
-  ` check.
+  ` check.
   Global options of the same name should be used instead.
 
 - Improved :doc:`modernize-loop-convert 
`



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


[clang-tools-extra] 7718422 - [clang-tidy] Improve rename_check.py

2023-01-23 Thread Carlos Galvez via cfe-commits

Author: Chris Cotter
Date: 2023-01-23T21:24:40Z
New Revision: 7718422d3b788a52b751773f464bfa52a6461fb7

URL: 
https://github.com/llvm/llvm-project/commit/7718422d3b788a52b751773f464bfa52a6461fb7
DIFF: 
https://github.com/llvm/llvm-project/commit/7718422d3b788a52b751773f464bfa52a6461fb7.diff

LOG: [clang-tidy] Improve rename_check.py

rename_check.py now find and renames the test file. rename_check.py
also will now use 'git mv', so the developer no longer has to manually
add the file after running the script.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D141463

Added: 


Modified: 
clang-tools-extra/clang-tidy/rename_check.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/rename_check.py 
b/clang-tools-extra/clang-tidy/rename_check.py
index ab37007ca014..764960e04421 100755
--- a/clang-tools-extra/clang-tidy/rename_check.py
+++ b/clang-tools-extra/clang-tidy/rename_check.py
@@ -93,12 +93,9 @@ def deleteMatchingLines(fileName, pattern):
 
 
 def getListOfFiles(clang_tidy_path):
-  files = glob.glob(os.path.join(clang_tidy_path, '*'))
-  for dirname in files:
-if os.path.isdir(dirname):
-  files += glob.glob(os.path.join(dirname, '*'))
+  files = glob.glob(os.path.join(clang_tidy_path, '**'), recursive=True)
   files += glob.glob(os.path.join(clang_tidy_path, '..', 'test',
-  'clang-tidy', '*'))
+  'clang-tidy', 'checkers', '**'), 
recursive=True)
   files += glob.glob(os.path.join(clang_tidy_path, '..', 'docs',
   'clang-tidy', 'checks', '*'))
   return [filename for filename in files if os.path.isfile(filename)]
@@ -273,10 +270,12 @@ def main():
 deleteMatchingLines(os.path.join(old_module_path, modulecpp),
   '\\b' + check_name_camel + '|\\b' + args.old_check_name)
 
+  old_check_filename = '-'.join(args.old_check_name.split('-')[1:])
+  new_check_filename = '-'.join(args.new_check_name.split('-')[1:])
+
   for filename in getListOfFiles(clang_tidy_path):
 originalName = filename
-filename = fileRename(filename, args.old_check_name,
-  args.new_check_name)
+filename = fileRename(filename, old_check_filename, new_check_filename)
 filename = fileRename(filename, check_name_camel, new_check_name_camel)
 replaceInFile(filename, generateCommentLineHeader(originalName),
   generateCommentLineHeader(filename))



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


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits


@@ -729,3 +729,21 @@ struct forward_declared_as_struct;
 class forward_declared_as_struct {
 };
 
+namespace pr55156 {
+
+typedef enum {
+  VALUE0,
+  VALUE1,
+} ValueType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for typedef 
'ValueType' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}} value_type_t;
+
+#define STATIC_MACRO static
+STATIC_MACRO void someFunc(ValueType a_v1, const ValueType& a_v2) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(value_type_t a_v1, const 
value_type_t& a_v2) {}
+STATIC_MACRO void someFunc(const ValueType** p_a_v1, ValueType (*p_a_v2)()) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(const value_type_t** p_a_v1, 
value_type_t (*p_a_v2)()) {}

carlosgalvezp wrote:

Shouldn't we add `CHECK-MESSAGES` here as well?

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


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits


@@ -729,3 +729,21 @@ struct forward_declared_as_struct;
 class forward_declared_as_struct {
 };
 
+namespace pr55156 {
+
+typedef enum {
+  VALUE0,
+  VALUE1,
+} ValueType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for typedef 
'ValueType' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}} value_type_t;
+
+#define STATIC_MACRO static
+STATIC_MACRO void someFunc(ValueType a_v1, const ValueType& a_v2) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(value_type_t a_v1, const 
value_type_t& a_v2) {}
+STATIC_MACRO void someFunc(const ValueType** p_a_v1, ValueType (*p_a_v2)()) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(const value_type_t** p_a_v1, 
value_type_t (*p_a_v2)()) {}

carlosgalvezp wrote:

Ack!

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


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp approved this pull request.

LGTM, thanks for the fix and the great cleanup!

https://github.com/llvm/llvm-project/pull/66835
___
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 recursion protection in ExceptionSpecAnalyzer (PR #66810)

2023-09-21 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Being totally unfamiliar with the code, I have a feeling that we shouldn't be 
fixing in the `analyze` function. `analyze` has 1 single responsibility: wrap 
`analyzeImpl` in order to add cacheability for performance reasons, and it does 
so simply and well, and it does exactly what one would expect - no more no less.

However, the real problem is that `analyzeImpl` ultimately might end up calling 
itself, via `analyzeUnresolvedOrDefaulted -> analyzeRecord -> analyze -> 
analyzeImpl` (IIRC). This is not obvious due to how the code is written, and 
this patch would make it even less obvious IMO. 

In that sense I believe it would make sense to ensure no recursion happens 
somewhere in the chain I described above, not in `analyze`. WDYT?

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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-22 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/67170

Casting an int into an enum is undefined behavior if the int is outside of the 
range of the enum. UB is not allowed in constant expressions, therefore the 
compiler must produce a hard error in that case.

However, until now, the compiler produced a warning that could be suppressed. 
It should instead be a hard error, since the program is ill-formed in that 
case, as per the C++ Standard.

This patch turns the warning into an error. Additionally, references to the old 
warning are removed since they are now meaningless.

Fixes #59036

>From b82f22ceee6d344bb3f808079c40193a6e3a12a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Fri, 22 Sep 2023 17:55:49 +
Subject: [PATCH] [clang] Turn -Wenum-constexpr-conversion into a hard error

Casting an int into an enum is undefined behavior if the int is
outside of the range of the enum. UB is not allowed in constant
expressions, therefore the compiler must produce a hard error
in that case.

However, until now, the compiler produced a warning that could be
suppressed. It should instead be a hard error, since the program
is ill-formed in that case, as per the C++ Standard.

This patch turns the warning into an error. Additionally, references
to the old warning are removed since they are now meaningless.

Fixes #59036
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 5 +++--
 clang/lib/AST/ExprConstant.cpp  | 4 ++--
 openmp/cmake/HandleOpenMPOptions.cmake  | 1 -
 openmp/cmake/config-ix.cmake| 1 -
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..1792a2c22261d63 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The downgradable error ``--Wenum-constexpr-conversion`` has been upgraded
+  into a hard error, to comply with the C++ Standard.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..58fbfef18e303ce 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -403,9 +403,10 @@ def warn_integer_constant_overflow : Warning<
 def warn_fixedpoint_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,
   InGroup>;
-def warn_constexpr_unscoped_enum_out_of_range : Warning<
+
+def err_constexpr_unscoped_enum_out_of_range : Error<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fea06b97259fe31..82d659aab28c7d0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13843,13 +13843,13 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
 (Max.slt(Result.getInt().getSExtValue()) ||
  Min.sgt(Result.getInt().getSExtValue(
   Info.Ctx.getDiagnostics().Report(
-  E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
+  E->getExprLoc(), diag::err_constexpr_unscoped_enum_out_of_range)
   << llvm::toString(Result.getInt(), 10) << Min.getSExtValue()
   << Max.getSExtValue() << ED;
 else if (!ED->getNumNegativeBits() && ConstexprVar &&
  Max.ult(Result.getInt().getZExtValue()))
   Info.Ctx.getDiagnostics().Report(
-  E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
+  E->getExprLoc(), diag::err_constexpr_unscoped_enum_out_of_range)
   << llvm::toString(Result.getInt(), 10) << Min.getZExtValue()
   << Max.getZExtValue() << ED;
   }
diff --git a/openmp/cmake/HandleOpenMPOptions.cmake 
b/openmp/cmake/HandleOpenMPOptions.cmake
index 4d6782a6f0cbe87..81b3d560acf6d8c 100644
--- a/openmp/cmake/HandleOpenMPOptions.cmake
+++ b/openmp/cmake/HandleOpenMPOptions.cmake
@@ -31,7 +31,6 @@ append_if(OPENMP_HAVE_WSIGN_COMPARE_FLAG "-Wsign-compare" 
CMAKE_C_FLAGS CMAKE_CX
 # printed. Therefore, check for whether the compiler supports options in the
 # form -W, and if supported, add the corresponding -Wno- option.
 
-append_if(OPENMP_HAVE_WENUM_CONSTEXPR_CONVERSION_FLAG 
"-Wno-enum-constexpr-conv

[clang-tools-extra] [clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (PR #66810)

2023-09-22 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

To clarify, I'm not concerned about performance, but with code readability and 
maintainability. 

I realize the chain that I wrote above should not lead to recursion due to 
`SkipMethods::Yes` in the relevant call. I'd like to take a closer look at the 
problem, would you be able to share some of the stacktrace that shows how the 
recursion is happening? 

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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-22 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Not sure what happens with the failed job in CI, I rebased on latest trunk and 
ran the entire `ninja check-clang` suite and it passed successfully. Do I need 
some special CMake configuration flag to enable the failing test?

About the patch itself - casting outside of range of enum is only UB since 
C++17 - before that it's unspecified. Do we want the error to throw always 
(this patch), or only in C++17 and on?

I started to put up a patch to filter this to only C++17, but then I thought: 
if the compiler is catching something bad, and it can warn about it, why 
shouldn't it?

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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-23 Thread Carlos Galvez via cfe-commits

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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-23 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks @shafik , I wasn't aware! I will then close this PR and continue the 
discussion on Phab.

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/67528

…macros

As per review comments on https://reviews.llvm.org/D150226, we should allow for 
one more release before turning this warning into a hard error, by making it 
visible in system headers and macros, so that people are aware of it and can 
work on it.

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits


@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

carlosgalvezp wrote:

Yes, will fix!

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/2] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 8dc78e7dda5d1db625eb45a8d32409fe1c91ea87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/2] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 



@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

carlosgalvezp wrote:

Done. 

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 8dc78e7dda5d1db625eb45a8d32409fe1c91ea87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

I would need some help with the failing pre-merge test, I don't really 
understand why that failure would be related to this patch...

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 7a70366e08f2c2f1181bb74f7716d8b1e3f1b62e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8f5a67e14c9aba3..6a1afa656a470b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 45fe235f06c4c1693e555baab2bedf233bef57e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

It seems checks are broken on trunk, I see commits merged with failing 
pre-merge tests. They seem to be unrelated to this patch though.

Is there anything else you'd like fixed before merging? @dwblaikie 
@AaronBallman @shafik 

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


[clang-tools-extra] b70e6e9 - [clang-tidy] Warn only for copyable/movable classes in cppcoreguidelines-avoid-const-or-ref-members

2023-07-19 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-19T12:05:15Z
New Revision: b70e6e9681925ad06d9899462b9e43250be53f64

URL: 
https://github.com/llvm/llvm-project/commit/b70e6e9681925ad06d9899462b9e43250be53f64
DIFF: 
https://github.com/llvm/llvm-project/commit/b70e6e9681925ad06d9899462b9e43250be53f64.diff

LOG: [clang-tidy] Warn only for copyable/movable classes in 
cppcoreguidelines-avoid-const-or-ref-members

Since that's what the guidelines require.

Fixes #63733

Differential Revision: https://reviews.llvm.org/D155625

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
index b22fa94663d584..6a6e620a4387b0 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
@@ -19,17 +19,86 @@ AST_MATCHER(FieldDecl, isMemberOfLambda) {
   return Node.getParent()->isLambda();
 }
 
+struct MemberFunctionInfo {
+  bool Declared{};
+  bool Deleted{};
+};
+
+struct MemberFunctionPairInfo {
+  MemberFunctionInfo Copy{};
+  MemberFunctionInfo Move{};
+};
+
+MemberFunctionPairInfo getConstructorsInfo(CXXRecordDecl const &Node) {
+  MemberFunctionPairInfo Constructors{};
+
+  for (CXXConstructorDecl const *Ctor : Node.ctors()) {
+if (Ctor->isCopyConstructor()) {
+  Constructors.Copy.Declared = true;
+  if (Ctor->isDeleted())
+Constructors.Copy.Deleted = true;
+}
+if (Ctor->isMoveConstructor()) {
+  Constructors.Move.Declared = true;
+  if (Ctor->isDeleted())
+Constructors.Move.Deleted = true;
+}
+  }
+
+  return Constructors;
+}
+
+MemberFunctionPairInfo getAssignmentsInfo(CXXRecordDecl const &Node) {
+  MemberFunctionPairInfo Assignments{};
+
+  for (CXXMethodDecl const *Method : Node.methods()) {
+if (Method->isCopyAssignmentOperator()) {
+  Assignments.Copy.Declared = true;
+  if (Method->isDeleted())
+Assignments.Copy.Deleted = true;
+}
+
+if (Method->isMoveAssignmentOperator()) {
+  Assignments.Move.Declared = true;
+  if (Method->isDeleted())
+Assignments.Move.Deleted = true;
+}
+  }
+
+  return Assignments;
+}
+
+AST_MATCHER(CXXRecordDecl, isCopyableOrMovable) {
+  MemberFunctionPairInfo Constructors = getConstructorsInfo(Node);
+  MemberFunctionPairInfo Assignments = getAssignmentsInfo(Node);
+
+  if (Node.hasSimpleCopyConstructor() ||
+  (Constructors.Copy.Declared && !Constructors.Copy.Deleted))
+return true;
+  if (Node.hasSimpleMoveConstructor() ||
+  (Constructors.Move.Declared && !Constructors.Move.Deleted))
+return true;
+  if (Node.hasSimpleCopyAssignment() ||
+  (Assignments.Copy.Declared && !Assignments.Copy.Deleted))
+return true;
+  if (Node.hasSimpleMoveAssignment() ||
+  (Assignments.Move.Declared && !Assignments.Move.Deleted))
+return true;
+
+  return false;
+}
+
 } // namespace
 
 void AvoidConstOrRefDataMembersCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
-   hasType(hasCanonicalType(referenceType(
- .bind("ref"),
- this);
-  Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
-   hasType(qualType(isConstQualified(
- .bind("const"),
- this);
+  Finder->addMatcher(
+  fieldDecl(
+  unless(isMemberOfLambda()),
+  anyOf(
+  
fieldDecl(hasType(hasCanonicalType(referenceType(.bind("ref"),
+  fieldDecl(hasType(qualType(isConstQualified(.bind("const")),
+  hasDeclContext(cxxRecordDecl(isCopyableOrMovable(,
+  this);
 }
 
 void AvoidConstOrRefDataMembersCheck::check(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1c542d4c9f2f30..1b8f3bf113c01c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -325,6 +325,11 @@ Changes in existing checks
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Fixed :doc:`cppcoreguidelines-avoid-const-or-ref-data-members
+  ` check
+  to emit warnings only on classes that are copyable/movable, as required by 
the
+  corresponding rule.
+
 - Deprecated C.48 enforcement from 
:doc:`cppcoreguidelines-prefer-member-initializer
   `. Please use
   :doc:`cppcoreguidelines-use-

[clang-tools-extra] b7c6b39 - [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

2023-07-26 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-26T10:26:43Z
New Revision: b7c6b39651b3ffdabf0081c45e0455a04a8be992

URL: 
https://github.com/llvm/llvm-project/commit/b7c6b39651b3ffdabf0081c45e0455a04a8be992
DIFF: 
https://github.com/llvm/llvm-project/commit/b7c6b39651b3ffdabf0081c45e0455a04a8be992.diff

LOG: [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

Since it was deprecated since clang-tidy 16.

Fixes #62020

Differential Revision: https://reviews.llvm.org/D156303

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index bc2ecc6b545536..1efe35a8b8f015 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -157,14 +157,12 @@ static void mapChecks(IO &IO, std::optional 
&Checks) {
 
 template <> struct MappingTraits {
   static void mapping(IO &IO, ClangTidyOptions &Options) {
-bool Ignored = false;
 mapChecks(IO, Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
-IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 159366222844ec..d22287d4effe49 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@ Improvements to clang-tidy
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was 
deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 

diff  --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
index 89d8f4400fca80..af4f66ae3c54f1 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@ TEST(ParseConfiguration, ValidConfiguration) {
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@ TEST(ParseConfiguration, MergeConfigurations) {
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@ TEST(ParseConfiguration, MergeConfigurations) {
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']



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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-13 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

Friendly ping @AaronBallman @shafik 

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-14 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 08b5c95bea5b7bfceeae6dfc4deac764faff87a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/2] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 4 
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1eebf5ea6b3e382..ade3c33b3b9444c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,10 @@ C++ Specific Potentially Breaking Changes
   Clang as a compiler, but it may break assumptions in Clang-based tools
   iterating over the AST.
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on
+  system headers and macros. It will be turned into a hard (non-downgradable)
+  error in the next Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 83d8ad39ee5544ad9bab848901362de0b180b2b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/2] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arit

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-14 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] 2992d08 - [clang-tidy] Do not warn on macros starting with underscore and lowercase letter in bugprone-reserved-identifier

2023-07-30 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-30T12:10:48Z
New Revision: 2992d084774f44e7626a7d640fe6c30163db450e

URL: 
https://github.com/llvm/llvm-project/commit/2992d084774f44e7626a7d640fe6c30163db450e
DIFF: 
https://github.com/llvm/llvm-project/commit/2992d084774f44e7626a7d640fe6c30163db450e.diff

LOG: [clang-tidy] Do not warn on macros starting with underscore and lowercase 
letter in bugprone-reserved-identifier

Fixes #64130

Differential Revision: https://reviews.llvm.org/D156608

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
index aaf10f63fb070d..fb04e6e0fa9361 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -102,13 +102,15 @@ static std::optional 
getUnderscoreCapitalFixup(StringRef Name) {
 }
 
 static bool startsWithUnderscoreInGlobalNamespace(StringRef Name,
-  bool IsInGlobalNamespace) {
-  return IsInGlobalNamespace && Name.size() >= 1 && Name[0] == '_';
+  bool IsInGlobalNamespace,
+  bool IsMacro) {
+  return !IsMacro && IsInGlobalNamespace && Name.size() >= 1 && Name[0] == '_';
 }
 
 static std::optional
-getUnderscoreGlobalNamespaceFixup(StringRef Name, bool IsInGlobalNamespace) {
-  if (startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace))
+getUnderscoreGlobalNamespaceFixup(StringRef Name, bool IsInGlobalNamespace,
+  bool IsMacro) {
+  if (startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace, 
IsMacro))
 return std::string(Name.drop_front(1));
   return std::nullopt;
 }
@@ -123,7 +125,7 @@ static std::string getNonReservedFixup(std::string Name) {
 }
 
 static std::optional
-getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace,
+getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace, bool IsMacro,
const LangOptions &LangOpts, bool Invert,
ArrayRef AllowedIdentifiers) {
   assert(!Name.empty());
@@ -158,15 +160,16 @@ getFailureInfoImpl(StringRef Name, bool 
IsInGlobalNamespace,
   AppendFailure(DoubleUnderscoreTag, std::move(*Fixup));
 if (auto Fixup = getUnderscoreCapitalFixup(InProgressFixup()))
   AppendFailure(UnderscoreCapitalTag, std::move(*Fixup));
-if (auto Fixup = getUnderscoreGlobalNamespaceFixup(InProgressFixup(),
-   IsInGlobalNamespace))
+if (auto Fixup = getUnderscoreGlobalNamespaceFixup(
+InProgressFixup(), IsInGlobalNamespace, IsMacro))
   AppendFailure(GlobalUnderscoreTag, std::move(*Fixup));
 
 return Info;
   }
   if (!(hasReservedDoubleUnderscore(Name, LangOpts) ||
 startsWithUnderscoreCapital(Name) ||
-startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace)))
+startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace,
+  IsMacro)))
 return FailureInfo{NonReservedTag, getNonReservedFixup(std::string(Name))};
   return std::nullopt;
 }
@@ -177,16 +180,17 @@ ReservedIdentifierCheck::getDeclFailureInfo(const 
NamedDecl *Decl,
   assert(Decl && Decl->getIdentifier() && !Decl->getName().empty() &&
  !Decl->isImplicit() &&
  "Decl must be an explicit identifier with a name.");
-  return getFailureInfoImpl(Decl->getName(),
-isa(Decl->getDeclContext()),
-getLangOpts(), Invert, AllowedIdentifiers);
+  return getFailureInfoImpl(
+  Decl->getName(), isa(Decl->getDeclContext()),
+  /*IsMacro = */ false, getLangOpts(), Invert, AllowedIdentifiers);
 }
 
 std::optional
 ReservedIdentifierCheck::getMacroFailureInfo(const Token &MacroNameTok,
  const SourceManager &) const {
   return getFailureInfoImpl(MacroNameTok.getIdentifierInfo()->getName(), true,
-getLangOpts(), Invert, AllowedIdentifiers);
+/*IsMacro = */ true, getLangOpts(), Invert,
+AllowedIdentifiers);
 }
 
 RenamerClangTidyCheck::DiagInfo

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a93ff58c60e2c0..000b80aadc0237 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -140,6 +140,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Fixed bug in :doc

[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

2023-09-08 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,34 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this check is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This check is under active development: the check authors made a few commits
+and are actively working on more commits. Users who want a mature and stable
+check should not use this check yet.
+
+This check is different from ProTypeMemberInitCheck in that this check

carlosgalvezp wrote:

ProTypeMemberInitCheck is an implementation detail - please refer to the 
user-facing check name (cppcoreguidelines-pro-type-member-init) together with a 
clickable link. Feel free to check out the Release Notes on how we typically 
refer to checks.

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


[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

2023-09-08 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,34 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this check is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This check is under active development: the check authors made a few commits
+and are actively working on more commits. Users who want a mature and stable
+check should not use this check yet.
+
+This check is different from ProTypeMemberInitCheck in that this check
+attempts to eliminate UUMs as a bug class, at the expense of false
+positives. The authors of this check will add more documentation about the
+differences with ProTypeMemberInitCheck as the check evolves.
+
+For now, this check reports `X` in the following two patterns:

carlosgalvezp wrote:

It would be good to show what the "fixed" code would look like.

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


[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

2023-09-08 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks for the detailed response @adriannistor !

> will soon become a lot of if-then-else blocks.

In general the decision as to which checks to have should be based on Coding 
Guidelines and user-facing experience - not on implementation complexity. In 
that sense, as a user I would find confusing to have 2 checks that do nearly 
the same.

If I understand the discussion correctly, the intention is to create a check 
that is stricter than the C++ Core Guidelines, is that correct? There is some 
vagueness in the Guidelines as well. Typically we handle this with Options, 
allowing users to enable a more strict or lenient version. Would that be an 
alternative?

Long-term, I believe we should just have 1 single check for "initialize your 
class members". This can be done in different ways, for example expanding the 
C++ Core Guidelines one, or replacing it with this new check (which should have 
relevant configuration options to ensure it behaves according to the spec of 
the Guidelines). I would be fine with temporarily having 2 checks in parallel 
as long as there's a plan for merging them eventually.

> If you would prefer that we write the checker until the end and then 
> upstream, we would be very glad to do that, just let me know!

I think it's great that you are splitting the development into smaller pieces 
so it's easier to do a quality review. Would it however make sense to keep a 
WIP documentation where one can see the approximate roadmap of this check, i.e 
what use cases are implemented and which ones will come? 




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


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-17 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp commented:

Should this change be reflected in the Release Notes?

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -1332,6 +1337,17 @@ void testBracedInitTemporaries() {
   v3.push_back(NonTrivialWithCtor{{}});
   v3.push_back({{0}});
   v3.push_back({{}});
+
+  std::vector v4;
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  v4.push_back(NonTrivialWithIntAndVector{});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{});

carlosgalvezp wrote:

We typically do not use `CHECK-FIXES` to ensure the code has not changed - the 
fact that a warning is not triggered should be enough (see rest of file).

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),

carlosgalvezp wrote:

Would it make sense to briefly document this choice of init list of exactly 0 
or 1 arguments in the line above?

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),

carlosgalvezp wrote:

Nit: would it be simpler/more readable with something like `initCountLeq(1)`?

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


[clang-tools-extra] [clang-tidy] readability-identifier-naming - fix StructCase and UnionCase in C (PR #65202)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/65202
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/65231:

…-delete

So the purpose of the check is more clear. Update examples code to show 
compliant code.

>From 0ffc7aab2f385babd81b57e8116b0433d85cfaf2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e253802..47de4185667a3e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp review_requested 
https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp review_requested 
https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp review_requested 
https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e253802..47de4185667a3e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp edited 
https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/2] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/2] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp resolved 
https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/3] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/3] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/3] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and keeping them in the ``public`` section.
-
-This check warns only on unimplemen

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/4] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/4] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/4] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and keeping them in the ``public`` section.
-
-This ch

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/5] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/5] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/5] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and keeping them in the ``

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 



@@ -3,22 +3,37 @@
 modernize-use-equals-delete
 ===
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
-
-.. code-block:: c++
-
-  struct A {
-  private:
+Identifies unimplemented private special member functions, and recommends using
+``= delete`` for them, as well as relocating them from the ``private`` to the
+``public`` section.
+
+Before the introduction of C++11, the primary method to effectively "erase" a
+particular function involved declaring it as ``private`` without providing a
+definition. This approach would result in either a compiler error (when
+attempting to call a private function) or a linker error (due to an undefined
+reference).
+
+However, subsequent to the advent of C++11, a more conventional approach 
emerged
+for achieving this purpose. It involves flagging functions as ``= delete`` and
+keeping them in the ``public`` section of the class.
+
+To prevent false positives, this check is only active within a translation
+unit where all other member functions have been implemented. The check will
+generate partial fixes by introducing ``= delete``, but the user is responsible
+for manually relocating functions to the ``public`` section.
+
+.. code-block:: c
+
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

carlosgalvezp wrote:

It's already documented on line 42, is there anything else you would like to 
add?

https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


carlosgalvezp wrote:

Yep, we could certainly change it to C++11 or later, but I think it's out of 
the scope for this NFC patch. Regarding documentation, I haven't seen that we 
document this detail in other checks, it seems like an implementation detail 
that could cause maintenance effort if documented.

https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 


carlosgalvezp wrote:

Yes good point, will fix!

https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/6] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e253802..47de4185667a3e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/6] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3e..a1fab68b0951b9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/6] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9..45039858fffdd3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and 

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-04 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/7] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/7] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/7] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking th

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-04 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp resolved 
https://github.com/llvm/llvm-project/pull/65231
___
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] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-04 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


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


[clang-tools-extra] [clang-tidy] Adding an initial version of the "Initialized Class Members" checker. (PR #65189)

2023-09-05 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this checker is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This checker is different from ProTypeMemberInitCheck in that this checker
+attempts to eliminate UUMs as a bug class, at the expense of false
+positives.

carlosgalvezp wrote:

It's not entirely clear to me what "UUMs as a bug class" means. Could you 
provide an example where `ProTypeMemberInitCheck` doesn't detect the problem, 
and this check does? Also, why shouldn't that be fixed in 
`ProTypeMemberInitCheck` instead?

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


[clang-tools-extra] 7e5c48b - [clang-tidy][NFC] Move avoid-underscore-in-googletest-name to google folder

2023-03-22 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-22T18:51:51Z
New Revision: 7e5c48b8bd9ff0ee5de3ba28c833f1225f14e44d

URL: 
https://github.com/llvm/llvm-project/commit/7e5c48b8bd9ff0ee5de3ba28c833f1225f14e44d
DIFF: 
https://github.com/llvm/llvm-project/commit/7e5c48b8bd9ff0ee5de3ba28c833f1225f14e44d.diff

LOG: [clang-tidy][NFC] Move avoid-underscore-in-googletest-name to google folder

Since the check belongs to the google module, it makes sense
that the corresponding test also belongs to the google module.

Differential Revision: https://reviews.llvm.org/D146653

Added: 

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Modified: 


Removed: 

clang-tools-extra/test/clang-tidy/checkers/readability/avoid-underscore-in-googletest-name.cpp



diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-underscore-in-googletest-name.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
similarity index 100%
rename from 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-underscore-in-googletest-name.cpp
rename to 
clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp



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


[clang-tools-extra] b08d35f - [clang-tidy] Ignore DISABLED_ in test suite name in google-avoid-underscore-in-googletest-name

2023-03-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-23T08:31:12Z
New Revision: b08d35f826a6b7696a02f1d811da7a2f951e74a1

URL: 
https://github.com/llvm/llvm-project/commit/b08d35f826a6b7696a02f1d811da7a2f951e74a1
DIFF: 
https://github.com/llvm/llvm-project/commit/b08d35f826a6b7696a02f1d811da7a2f951e74a1.diff

LOG: [clang-tidy] Ignore DISABLED_ in test suite name in 
google-avoid-underscore-in-googletest-name

Test suite name can also be disabled with DISABLED_, not just
the test case name.

Fix also broken link in the test that refers to the explanation
as to why underscores may not be used.

Differential Revision: https://reviews.llvm.org/D146655

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
index c5bd6055072aa..b903f2552b7e6 100644
--- 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -51,8 +51,10 @@ class AvoidUnderscoreInGoogletestNameCallback : public 
PPCallbacks {
 const Token *TestNameToken = Args->getUnexpArgument(1);
 if (!TestCaseNameToken || !TestNameToken)
   return;
-std::string TestCaseName = PP->getSpelling(*TestCaseNameToken);
-if (TestCaseName.find('_') != std::string::npos)
+std::string TestCaseNameMaybeDisabled = 
PP->getSpelling(*TestCaseNameToken);
+StringRef TestCaseName = TestCaseNameMaybeDisabled;
+TestCaseName.consume_front(KDisabledTestPrefix);
+if (TestCaseName.contains('_'))
   Check->diag(TestCaseNameToken->getLocation(),
   "avoid using \"_\" in test case name \"%0\" according to "
   "Googletest FAQ")

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3f79e8e2a187a..80f5b46681713 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -234,6 +234,10 @@ Changes in existing checks
   string for ``Prefix`` or ``Suffix`` options could result in the style not
   being used.
 
+- Fixed an issue in :doc:`google-avoid-underscore-in-googletest-name
+  ` when using
+  ``DISABLED_`` in the test suite name.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
index 6e8a5c2d50af9..3ab5a6ffe383b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
@@ -87,21 +87,31 @@ TYPED_TEST_P(Illegal_Type_ParameterizedTestCaseName, 
TestName) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: avoid using "_" in test case name 
"Illegal_Type_ParameterizedTestCaseName" according to Googletest FAQ 
[google-readability-avoid-underscore-in-googletest-name]
 
 // Underscores are allowed to disable a test with the DISABLED_ prefix.
-// 
https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-suite-names-and-test-names-not-contain-underscore
+// 
https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore
 TEST(TestCaseName, TestName) {}
 TEST(TestCaseName, DISABLED_TestName) {}
+TEST(DISABLED_TestCaseName, TestName) {}
+TEST(DISABLED_TestCaseName, DISABLED_TestName) {}
 
 TEST_F(TestCaseFixtureName, TestName) {}
 TEST_F(TestCaseFixtureName, DISABLED_TestName) {}
+TEST_F(DISABLED_TestCaseFixtureName, TestName) {}
+TEST_F(DISABLED_TestCaseFixtureName, DISABLED_TestName) {}
 
 TEST_P(ParameterizedTestCaseFixtureName, TestName) {}
 TEST_P(ParameterizedTestCaseFixtureName, DISABLED_TestName) {}
+TEST_P(DISABLED_ParameterizedTestCaseFixtureName, TestName) {}
+TEST_P(DISABLED_ParameterizedTestCaseFixtureName, DISABLED_TestName) {}
 
 TYPED_TEST(TypedTestName, TestName) {}
 TYPED_TEST(TypedTestName, DISABLED_TestName) {}
+TYPED_TEST(DISABLED_TypedTestName, TestName) {}
+TYPED_TEST(DISABLED_TypedTestName, DISABLED_TestName) {}
 
 TYPED_TEST_P(TypeParameterizedTestName, TestName) {}
 TYPED_TEST_P(TypeParameterizedTestName, DISABLED_TestName) {}
+TYPED_TEST_P(DISABLED_TypeParameterizedTestName, TestName) {}
+TYPED_TEST_P(DISABLED_TypeParameterizedTestName, DISABLED_TestName) {}
 
 FRIEND_TEST(FriendTest, Is_NotChecked) {}
 FRIEND_TEST(Friend_Test, IsNotChecked) {}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists

[clang-tools-extra] b767784 - [clang-tidy][NFC] Fix broken link in Release Notes

2023-03-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-23T10:30:15Z
New Revision: b7677846da66fd003a538f87fd8de948cfcc3d6a

URL: 
https://github.com/llvm/llvm-project/commit/b7677846da66fd003a538f87fd8de948cfcc3d6a
DIFF: 
https://github.com/llvm/llvm-project/commit/b7677846da66fd003a538f87fd8de948cfcc3d6a.diff

LOG: [clang-tidy][NFC] Fix broken link in Release Notes

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 89419141cebb..a5f090045615 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -238,8 +238,8 @@ Changes in existing checks
   string for ``Prefix`` or ``Suffix`` options could result in the style not
   being used.
 
-- Fixed an issue in :doc:`google-avoid-underscore-in-googletest-name
-  ` when using
+- Fixed an issue in 
:doc:`google-readability-avoid-underscore-in-googletest-name
+  ` 
when using
   ``DISABLED_`` in the test suite name.
 
 Removed checks



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


[clang-tools-extra] f957b8f - [clang-tidy][NFC] Improve naming convention in google-readability-avoid-underscore-in-googletest-name

2023-03-24 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-24T07:22:04Z
New Revision: f957b8fe1efe34ac04d1b2e6381e44edcef056b3

URL: 
https://github.com/llvm/llvm-project/commit/f957b8fe1efe34ac04d1b2e6381e44edcef056b3
DIFF: 
https://github.com/llvm/llvm-project/commit/f957b8fe1efe34ac04d1b2e6381e44edcef056b3.diff

LOG: [clang-tidy][NFC] Improve naming convention in 
google-readability-avoid-underscore-in-googletest-name

According to the Google docs, the convention is
TEST(TestSuiteName, TestName). Apply that convention to the
source code, test and documentation of the check.

Differential Revision: https://reviews.llvm.org/D146713

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
index b903f2552b7e..d522d6760af1 100644
--- 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -47,18 +47,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public 
PPCallbacks {
 if (!isGoogletestTestMacro(MacroName) || !Args ||
 Args->getNumMacroArguments() < 2)
   return;
-const Token *TestCaseNameToken = Args->getUnexpArgument(0);
+const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
 const Token *TestNameToken = Args->getUnexpArgument(1);
-if (!TestCaseNameToken || !TestNameToken)
+if (!TestSuiteNameToken || !TestNameToken)
   return;
-std::string TestCaseNameMaybeDisabled = 
PP->getSpelling(*TestCaseNameToken);
-StringRef TestCaseName = TestCaseNameMaybeDisabled;
-TestCaseName.consume_front(KDisabledTestPrefix);
-if (TestCaseName.contains('_'))
-  Check->diag(TestCaseNameToken->getLocation(),
-  "avoid using \"_\" in test case name \"%0\" according to "
+std::string TestSuiteNameMaybeDisabled =
+PP->getSpelling(*TestSuiteNameToken);
+StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
+TestSuiteName.consume_front(KDisabledTestPrefix);
+if (TestSuiteName.contains('_'))
+  Check->diag(TestSuiteNameToken->getLocation(),
+  "avoid using \"_\" in test suite name \"%0\" according to "
   "Googletest FAQ")
-  << TestCaseName;
+  << TestSuiteName;
 
 std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
 StringRef TestName = TestNameMaybeDisabled;

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
index f2053b4d2fcd..e667fd1b 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
@@ -3,8 +3,8 @@
 google-readability-avoid-underscore-in-googletest-name
 ==
 
-Checks whether there are underscores in googletest test and test case names in
-test macros:
+Checks whether there are underscores in googletest test suite names and test
+names in test macros:
 
 - ``TEST``
 - ``TEST_F``
@@ -18,17 +18,17 @@ For example:
 
 .. code-block:: c++
 
-  TEST(TestCaseName, Illegal_TestName) {}
-  TEST(Illegal_TestCaseName, TestName) {}
+  TEST(TestSuiteName, Illegal_TestName) {}
+  TEST(Illegal_TestSuiteName, TestName) {}
 
-would trigger the check. `Underscores are not allowed`_ in test names nor test
-case names.
+would trigger the check. `Underscores are not allowed`_ in test suite name nor
+test names.
 
-The ``DISABLED_`` prefix, which may be used to `disable individual tests`_, is
-ignored when checking test names, but the rest of the rest of the test name is
-still checked.
+The ``DISABLED_`` prefix, which may be used to
+`disable test suites and individual tests`_, is removed from the test suite 
name
+and test name before checking for underscores.
 
 This check does not propose any fixes.
 
 .. _Underscores are not allowed: 
https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore
-.. _disable individual tests: 
https://google.github.io/googletest/advanced.html#temporarily-disabling-tests
+.. _disable test suites and individual tests: 
https://google.github.io/googletest/advanced.html#temporarily-disabling-tests

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-nam

[clang-tools-extra] 556600a - [clang-tidy] Add option to ignore user-defined literals in readability-magic-numbers

2023-03-26 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-26T16:41:17Z
New Revision: 556600af6a8a7f241277f7a22c3e3746e7b09123

URL: 
https://github.com/llvm/llvm-project/commit/556600af6a8a7f241277f7a22c3e3746e7b09123
DIFF: 
https://github.com/llvm/llvm-project/commit/556600af6a8a7f241277f7a22c3e3746e7b09123.diff

LOG: [clang-tidy] Add option to ignore user-defined literals in 
readability-magic-numbers

Some user-defined literals operate on implementation-defined types, like
"unsigned long long" and "long double", which are not well supported by
this check. Currently, the check gives warnings when using UDLs, without
giving possiblity to the user to whitelist common UDLs. A good compromise
until a proper fix is found (if any) is to allow the user to disable
warnings on UDLs.

Partially fixes #61656

Differential Revision: https://reviews.llvm.org/D146913

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst

clang-tools-extra/test/clang-tidy/checkers/readability/magic-numbers-userliteral.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index ca81b6e3c6e61..cffe858c39ad1 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -81,6 +81,8 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, 
ClangTidyContext *Context)
   IgnorePowersOf2IntegerValues(
   Options.get("IgnorePowersOf2IntegerValues", false)),
   IgnoreTypeAliases(Options.get("IgnoreTypeAliases", false)),
+  IgnoreUserDefinedLiterals(
+  Options.get("IgnoreUserDefinedLiterals", false)),
   RawIgnoredIntegerValues(
   Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues)),
   RawIgnoredFloatingPointValues(Options.get(
@@ -130,6 +132,7 @@ void 
MagicNumbersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnorePowersOf2IntegerValues",
 IgnorePowersOf2IntegerValues);
   Options.store(Opts, "IgnoreTypeAliases", IgnoreTypeAliases);
+  Options.store(Opts, "IgnoreUserDefinedLiterals", IgnoreUserDefinedLiterals);
   Options.store(Opts, "IgnoredIntegerValues", RawIgnoredIntegerValues);
   Options.store(Opts, "IgnoredFloatingPointValues",
 RawIgnoredFloatingPointValues);
@@ -243,5 +246,14 @@ bool MagicNumbersCheck::isBitFieldWidth(
   });
 }
 
+bool MagicNumbersCheck::isUserDefinedLiteral(
+const clang::ast_matchers::MatchFinder::MatchResult &Result,
+const clang::Expr &Literal) const {
+  DynTypedNodeList Parents = Result.Context->getParents(Literal);
+  if (Parents.empty())
+return false;
+  return Parents[0].get() != nullptr;
+}
+
 } // namespace tidy::readability
 } // namespace clang

diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
index 39e9baea3adc8..79787845de619 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
@@ -49,6 +49,10 @@ class MagicNumbersCheck : public ClangTidyCheck {
   bool isBitFieldWidth(const clang::ast_matchers::MatchFinder::MatchResult 
&Result,
const IntegerLiteral &Literal) const;
 
+  bool isUserDefinedLiteral(
+  const clang::ast_matchers::MatchFinder::MatchResult &Result,
+  const clang::Expr &Literal) const;
+
   template 
   void checkBoundMatch(const ast_matchers::MatchFinder::MatchResult &Result,
const char *BoundName) {
@@ -72,6 +76,10 @@ class MagicNumbersCheck : public ClangTidyCheck {
 if (isBitFieldWidth(Result, *MatchedLiteral))
   return;
 
+if (IgnoreUserDefinedLiterals &&
+isUserDefinedLiteral(Result, *MatchedLiteral))
+  return;
+
 const StringRef LiteralSourceText = Lexer::getSourceText(
 CharSourceRange::getTokenRange(MatchedLiteral->getSourceRange()),
 *Result.SourceManager, getLangOpts());
@@ -85,6 +93,7 @@ class MagicNumbersCheck : public ClangTidyCheck {
   const bool IgnoreBitFieldsWidths;
   const bool IgnorePowersOf2IntegerValues;
   const bool IgnoreTypeAliases;
+  const bool IgnoreUserDefinedLiterals;
   const StringRef RawIgnoredIntegerValues;
   const StringRef RawIgnoredFloatingPointValues;
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1a53aac8fecf4..03ba9e160b738 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -223,6 +223,9 @@ Changes in existing checks
   behavior of us

[clang-tools-extra] 4d4c0f9 - [clang-tidy] Add option to ignore capture default by reference in cppcoreguidelines-avoid-capture-default-when-capturing-this

2023-03-28 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-28T20:36:34Z
New Revision: 4d4c0f9734607bb0423593b060b8fa73c06fe3d3

URL: 
https://github.com/llvm/llvm-project/commit/4d4c0f9734607bb0423593b060b8fa73c06fe3d3
DIFF: 
https://github.com/llvm/llvm-project/commit/4d4c0f9734607bb0423593b060b8fa73c06fe3d3.diff

LOG: [clang-tidy] Add option to ignore capture default by reference in 
cppcoreguidelines-avoid-capture-default-when-capturing-this

The rule exists primarily for when using capture default
by copy "[=]", since member variables will be captured by
reference, which is against developer expectations.

However when the capture default is by reference, then there
is no doubt: everything will be captured by reference. Add
an option to allow just that.

Note: Release Notes do not need update since this check
has been introduced in the current WIP release.

A ticket has been opened at the C++ Core Guidelines repo
to consider updating the rule such that this behavior
is the default one:
https://github.com/isocpp/CppCoreGuidelines/issues/2060

Differential Revision: https://reviews.llvm.org/D147062

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
index 11ef35178765f..1489ca6c442b1 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
@@ -18,6 +18,19 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+AvoidCaptureDefaultWhenCapturingThisCheck::
+AvoidCaptureDefaultWhenCapturingThisCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreCaptureDefaultByReference(
+  Options.get("IgnoreCaptureDefaultByReference", false)) {}
+
+void AvoidCaptureDefaultWhenCapturingThisCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreCaptureDefaultByReference",
+IgnoreCaptureDefaultByReference);
+}
+
 void AvoidCaptureDefaultWhenCapturingThisCheck::registerMatchers(
 MatchFinder *Finder) {
   Finder->addMatcher(lambdaExpr(hasAnyCapture(capturesThis())).bind("lambda"),
@@ -74,24 +87,30 @@ static std::string createReplacementText(const LambdaExpr 
*Lambda) {
 
 void AvoidCaptureDefaultWhenCapturingThisCheck::check(
 const MatchFinder::MatchResult &Result) {
-  if (const auto *Lambda = Result.Nodes.getNodeAs("lambda")) {
-if (Lambda->getCaptureDefault() != LCD_None) {
-  bool IsThisImplicitlyCaptured = std::any_of(
-  Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
-  [](const LambdaCapture &Capture) { return Capture.capturesThis(); });
-  auto Diag = diag(Lambda->getCaptureDefaultLoc(),
-   "lambdas that %select{|implicitly }0capture 'this' "
-   "should not specify a capture default")
-  << IsThisImplicitlyCaptured;
-
-  std::string ReplacementText = createReplacementText(Lambda);
-  SourceLocation DefaultCaptureEnd =
-  findDefaultCaptureEnd(Lambda, *Result.Context);
-  Diag << FixItHint::CreateReplacement(
-  CharSourceRange::getCharRange(Lambda->getCaptureDefaultLoc(),
-DefaultCaptureEnd),
-  ReplacementText);
-}
+  const auto *Lambda = Result.Nodes.getNodeAs("lambda");
+  if (!Lambda)
+return;
+
+  if (IgnoreCaptureDefaultByReference &&
+  Lambda->getCaptureDefault() == LCD_ByRef)
+return;
+
+  if (Lambda->getCaptureDefault() != LCD_None) {
+bool IsThisImplicitlyCaptured = std::any_of(
+Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
+[](const LambdaCapture &Capture) { return Capture.capturesThis(); });
+auto Diag = diag(Lambda->getCaptureDefaultLoc(),
+ "lambdas that %select{|implicitly }0capture 'this' "
+ "should not specify a capture default")
+<< IsThisImplicitlyCaptured;
+
+std::string ReplacementText = createReplacementText(Lambda);
+SourceLocation DefaultCaptureEnd =
+findDefaultCaptureEnd(Lambda, *Result.Context);
+Diag << FixItHint::CreateReplacement(
+CharSourceRange::getCharRange(L

[clang-tools-extra] 00a71cb - [clang-tidy] readability-identifier-naming.HungarianNotation: rename CharPrinter to CharPointer

2023-02-26 Thread Carlos Galvez via cfe-commits

Author: Alexis Murzeau
Date: 2023-02-26T08:22:56Z
New Revision: 00a71cb47c36984dcd9f51492e1e831aec0e0460

URL: 
https://github.com/llvm/llvm-project/commit/00a71cb47c36984dcd9f51492e1e831aec0e0460
DIFF: 
https://github.com/llvm/llvm-project/commit/00a71cb47c36984dcd9f51492e1e831aec0e0460.diff

LOG: [clang-tidy] readability-identifier-naming.HungarianNotation: rename 
CharPrinter to CharPointer

The CharPrinter is a typo and should have been named CharPointer as it
configures the hungarian notation prefix for char pointers (char*).

As all configuration options within
readability-identifier-naming.HungarianNotation.CString.* were not read
at all in the previous clang-tidy version (fixed in D144431), this option
rename won't break existing users.

A note in release notes is added to let users know these options were
renamed.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D144790

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst

clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index dd9a4fa9b8e30..61421a13d73ba 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -460,9 +460,9 @@ void 
IdentifierNamingCheck::HungarianNotation::loadFileConfig(
   }
 
   static constexpr std::pair HNCStrings[] = {
-  {"CharPrinter", "char*"},
+  {"CharPointer", "char*"},
   {"CharArray", "char[]"},
-  {"WideCharPrinter", "wchar_t*"},
+  {"WideCharPointer", "wchar_t*"},
   {"WideCharArray", "wchar_t[]"}};
 
   Buffer = {Section, "CString."};

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 4906d2c78cfaf..5979b9e6d592d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,6 +173,11 @@ Changes in existing checks
   :doc:`readability-identifier-naming
   ` check.
 
+- Renamed `HungarianNotation.CString` options `CharPrinter` and
+  `WideCharPrinter` to `CharPointer` and `WideCharPointer` respectively in
+  :doc:`readability-identifier-naming
+  ` check.
+
 - Fixed a false positive in :doc:`readability-container-size-empty
   ` check when comparing
   ``std::array`` objects to default constructed ones. The behavior for this and

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
index 3f98ed73dd953..621fe0258e277 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
@@ -2584,9 +2584,9 @@ Options for Hungarian Notation
 - :option:`HungarianNotation.DerivedType.Pointer`
 - :option:`HungarianNotation.DerivedType.FunctionPointer`
 
-- :option:`HungarianNotation.CString.CharPrinter`
+- :option:`HungarianNotation.CString.CharPointer`
 - :option:`HungarianNotation.CString.CharArray`
-- :option:`HungarianNotation.CString.WideCharPrinter`
+- :option:`HungarianNotation.CString.WideCharPointer`
 - :option:`HungarianNotation.CString.WideCharArray`
 
 - :option:`HungarianNotation.PrimitiveType.*`
@@ -2642,7 +2642,7 @@ After:
 FUNC_PTR fnFuncPtr = NULL;
 
 
-.. option:: HungarianNotation.CString.CharPrinter
+.. option:: HungarianNotation.CString.CharPointer
 
 When defined, the check will ensure variable name will add the prefix with
 the given string. The default prefix is `sz`.
@@ -2652,7 +2652,7 @@ After:
 When defined, the check will ensure variable name will add the prefix with
 the given string. The default prefix is `sz`.
 
-.. option:: HungarianNotation.CString.WideCharPrinter
+.. option:: HungarianNotation.CString.WideCharPointer
 
 When defined, the check will ensure variable name will add the prefix with
 the given string. The default prefix is `wsz`.
@@ -2667,13 +2667,13 @@ Before:
 
 .. code-block:: c++
 
-// CharPrinter
+// CharPointer
 const char *NamePtr = "Name";
 
 // CharArray
 const char NameArray[] = "Name";
 
-// WideCharPrinter
+// WideCharPointer
 const wchar_t *WideNamePtr = L"Name";
 
 // WideCharArray
@@ -2683,13 +2683,13 @@ After:
 
 .. code-block:: c++
 
-// CharPrinter
+// CharPointer
 const char *szNamePtr = "Name";
 
 // CharArray
 const char szNameArray[] = "Name";
 
-// WideCharPrinter
+// WideCharPointer
 const wchar_t *wszWideNamePtr = L"Name";
 
  

[clang-tools-extra] c6d195b - clang-tidy altera-id-dependent-backward-branch: print notes after warning

2023-03-05 Thread Carlos Galvez via cfe-commits

Author: Egor Suvorov
Date: 2023-03-05T16:06:55Z
New Revision: c6d195b366c8256184ff40c5e46339eed96b4a81

URL: 
https://github.com/llvm/llvm-project/commit/c6d195b366c8256184ff40c5e46339eed96b4a81
DIFF: 
https://github.com/llvm/llvm-project/commit/c6d195b366c8256184ff40c5e46339eed96b4a81.diff

LOG: clang-tidy altera-id-dependent-backward-branch: print notes after warning

In Clang notes are typically printed after a corresponding warning, not before.
For example, all notes issued before the first warning are ignored.

Running `clang-tidy --checks=-*,altera-id-dependent-backward-branch a.cpp` on 
the following code:
```
long get_local_id(int);
void error() {
  int ThreadID = get_local_id(0);
  for (int i = 0; i < ThreadID; i++) {
  }
  for (int i = 0; i < ThreadID; i++) {
  }
}
```
results in two warnings and a single note in between.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D145303

Added: 


Modified: 
clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp 
b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
index 66e6d97f500ce..f9225f6ba7f47 100644
--- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -241,18 +241,17 @@ void IdDependentBackwardBranchCheck::check(
 IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
 IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
 if (IdDepVar) {
-  // Change one of these to a Note
-  diag(IdDepVar->Location, IdDepVar->Message, DiagnosticIDs::Note);
   diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to variable reference to %1 and may cause performance degradation")
   << Type << IdDepVar->VariableDeclaration;
+  diag(IdDepVar->Location, IdDepVar->Message, DiagnosticIDs::Note);
 } else if (IdDepField) {
-  diag(IdDepField->Location, IdDepField->Message, DiagnosticIDs::Note);
   diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to member reference to %1 and may cause performance degradation")
   << Type << IdDepField->FieldDeclaration;
+  diag(IdDepField->Location, IdDepField->Message, DiagnosticIDs::Note);
 }
   }
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
index 68f4658a7dc9b..0c7a20ad6a179 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -27,8 +27,8 @@ void error() {
   int ThreadID = get_local_id(0);
 
   while (j < ThreadID) {
-// CHECK-NOTES: :[[@LINE-3]]:3: note: assignment of ID-dependent variable 
ThreadID
-// CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-4]]:3: note: assignment of ID-dependent variable 
ThreadID
 accumulator++;
   }
 
@@ -45,34 +45,34 @@ void error() {
   };
 
   for (int i = 0; i < ThreadID2; i++) {
-// CHECK-NOTES: :[[@LINE-9]]:3: note: inferred assignment of ID-dependent 
value from ID-dependent variable ThreadID
-// CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is 
ID-dependent due to variable reference to 'ThreadID2' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is 
ID-dependent due to variable reference to 'ThreadID2' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-10]]:3: note: inferred assignment of ID-dependent 
value from ID-dependent variable ThreadID
 accumulator++;
   }
 
   do {
 accumulator++;
   } while (j < ThreadID);
-  // CHECK-NOTES: :[[@LINE-29]]:3: note: assignment of ID-dependent variable 
ThreadID
-  // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+  // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is 
ID-d

  1   2   3   4   5   >