[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang-tools-extra.

  struct XY {
int *x;
int *y;
  };
  void recordInitList(int *x) {
XY xy = {x, nullptr};
  }

x cannot be const int* becase it in a initialize list which only accept int*


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551030.
HerrCai0907 added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,10 @@
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,10 @@
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551344.
HerrCai0907 added a comment.

update release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158244: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added reviewers: njames93, PiotrZSL, aaron.ballman, Eugene.Zelenko.
Herald added subscribers: carlosgalvezp, kbarton, xazax.hun, nemanjai.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

cast PredefinedExpr such as `__func__` to const char* should be accpetted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158244

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` 
check 
+  to ignore predefined expression (e.g., __func__, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` check 
+  to ignore predefined expression (e.g., __func__, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,
___
cfe

[PATCH] D158244: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551379.
HerrCai0907 added a comment.

update release-note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158244/new/

https://reviews.llvm.org/D158244

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` 
check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158244: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression

2023-08-18 Thread Congcong Cai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9be33de4f397: 
[clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression 
(authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158244/new/

https://reviews.llvm.org/D158244

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` 
check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-19 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551802.
HerrCai0907 added a comment.

fix typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158480: [clang-tidy][readability-braces-around-statements] ignore false-positive for constexpr if statement in lambda expression

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixed: #64545

When TreeTransform, Stmt in constexpr IfStmt will be transform to NullStmt.
This NullStmt has the different beginning token.
This patch add addtional check in checkStmt to handle this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158480

Files:
  clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
@@ -457,3 +457,25 @@
   // CHECK-FIXES-NEXT: }
 
 }
+
+template 
+auto constexpr_lambda_1 = [] {
+  if constexpr (A) {
+1;
+  }
+};
+
+template 
+auto constexpr_lambda_2 = [] {
+  // CHECK-MESSAGES: :[[@LINE+1]]:19: warning: statement should be inside 
braces
+  if constexpr (A)
+1;
+  // CHECK-FIXES:if constexpr (A) {
+  // CHECK-FIXES-NEXT:1;
+  // CHECK-FIXES-NEXT:}
+};
+
+void test_constexpr() {
+  constexpr_lambda_1();
+  constexpr_lambda_2();
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-braces-around-statements
+  ` check to
+  ignore false-positive for constexpr if statement in lambda expression.
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals.
Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -192,6 +192,9 @@
   while (const auto *AS = dyn_cast(S))
 S = AS->getSubStmt();
 
+  const SourceManager &SM = *Result.SourceManager;
+  const ASTContext *Context = Result.Context;
+
   // 1) If there's a corresponding "else" or "while", the check inserts "} "
   // right before that token.
   // 2) If there's a multi-line block comment starting on the same line after
@@ -204,10 +207,15 @@
 return false;
   }
 
+  // When TreeTransform, Stmt in constexpr IfStmt will be transform to 
NullStmt.
+  // This NullStmt can be detected according to beginning token.
+  const SourceLocation StmtBeginLoc = S->getBeginLoc();
+  if (isa(S) && StmtBeginLoc.isValid() &&
+  getTokenKind(StmtBeginLoc, SM, Context) == tok::l_brace)
+return false;
+
   if (!InitialLoc.isValid())
 return false;
-  const SourceManager &SM = *Result.SourceManager;
-  const ASTContext *Context = Result.Context;
 
   // Convert InitialLoc to file location, if it's on the same macro expansion
   // level as the start of the statement. We also need file locations for


Index: clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
@@ -457,3 +457,25 @@
   // CHECK-FIXES-NEXT: }
 
 }
+
+template 
+auto constexpr_lambda_1 = [] {
+  if constexpr (A) {
+1;
+  }
+};
+
+template 
+auto constexpr_lambda_2 = [] {
+  // CHECK-MESSAGES: :[[@LINE+1]]:19: warning: statement should be inside braces
+  if constexpr (A)
+1;
+  // CHECK-FIXES:if constexpr (A) {
+  // CHECK-FIXES-NEXT:1;
+  // CHECK-FIXES-NEXT:}
+};
+
+void test_constexpr() {
+  constexpr_lambda_1();
+  constexpr_lambda_2();
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-braces-around-statements
+  ` check to
+  ignore false-positive for constexpr if statement in lambda expression.
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals.
Index: clang-tools-extra/clang-tidy/re

[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 552199.
HerrCai0907 added a comment.

add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 

[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c9412441b87: [clang-tidy]mark record initList as non-const 
param (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointee

[PATCH] D158480: [clang-tidy][readability-braces-around-statements] ignore false-positive for constexpr if statement in lambda expression

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 552227.
HerrCai0907 added a comment.

update release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158480/new/

https://reviews.llvm.org/D158480

Files:
  clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
@@ -457,3 +457,25 @@
   // CHECK-FIXES-NEXT: }
 
 }
+
+template 
+auto constexpr_lambda_1 = [] {
+  if constexpr (A) {
+1;
+  }
+};
+
+template 
+auto constexpr_lambda_2 = [] {
+  // CHECK-MESSAGES: :[[@LINE+1]]:19: warning: statement should be inside 
braces
+  if constexpr (A)
+1;
+  // CHECK-FIXES:if constexpr (A) {
+  // CHECK-FIXES-NEXT:1;
+  // CHECK-FIXES-NEXT:}
+};
+
+void test_constexpr() {
+  constexpr_lambda_1();
+  constexpr_lambda_2();
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-braces-around-statements
+  ` check to
+  ignore false-positive for ``if constexpr`` in lambda expression.
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals.
Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -192,6 +192,9 @@
   while (const auto *AS = dyn_cast(S))
 S = AS->getSubStmt();
 
+  const SourceManager &SM = *Result.SourceManager;
+  const ASTContext *Context = Result.Context;
+
   // 1) If there's a corresponding "else" or "while", the check inserts "} "
   // right before that token.
   // 2) If there's a multi-line block comment starting on the same line after
@@ -204,10 +207,15 @@
 return false;
   }
 
+  // When TreeTransform, Stmt in constexpr IfStmt will be transform to 
NullStmt.
+  // This NullStmt can be detected according to beginning token.
+  const SourceLocation StmtBeginLoc = S->getBeginLoc();
+  if (isa(S) && StmtBeginLoc.isValid() &&
+  getTokenKind(StmtBeginLoc, SM, Context) == tok::l_brace)
+return false;
+
   if (!InitialLoc.isValid())
 return false;
-  const SourceManager &SM = *Result.SourceManager;
-  const ASTContext *Context = Result.Context;
 
   // Convert InitialLoc to file location, if it's on the same macro expansion
   // level as the start of the statement. We also need file locations for


Index: clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
@@ -457,3 +457,25 @@
   // CHECK-FIXES-NEXT: }
 
 }
+
+template 
+auto constexpr_lambda_1 = [] {
+  if constexpr (A) {
+1;
+  }
+};
+
+template 
+auto constexpr_lambda_2 = [] {
+  // CHECK-MESSAGES: :[[@LINE+1]]:19: warning: statement should be inside braces
+  if constexpr (A)
+1;
+  // CHECK-FIXES:if constexpr (A) {
+  // CHECK-FIXES-NEXT:1;
+  // CHECK-FIXES-NEXT:}
+};
+
+void test_constexpr() {
+  constexpr_lambda_1();
+  constexpr_lambda_2();
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-braces-around-statements
+  ` check to
+  ignore false-positive for ``if constexpr`` in lambda expression.
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals.
Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -192,6 +192,9 @@
   while (const auto *AS = dyn_cast(S))
 S = AS->getSu

[PATCH] D158480: [clang-tidy][readability-braces-around-statements] ignore false-positive for constexpr if statement in lambda expression

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9b6859dc89b9: 
[clang-tidy][readability-braces-around-statements] ignore false-positive for… 
(authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158480/new/

https://reviews.llvm.org/D158480

Files:
  clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
@@ -457,3 +457,25 @@
   // CHECK-FIXES-NEXT: }
 
 }
+
+template 
+auto constexpr_lambda_1 = [] {
+  if constexpr (A) {
+1;
+  }
+};
+
+template 
+auto constexpr_lambda_2 = [] {
+  // CHECK-MESSAGES: :[[@LINE+1]]:19: warning: statement should be inside 
braces
+  if constexpr (A)
+1;
+  // CHECK-FIXES:if constexpr (A) {
+  // CHECK-FIXES-NEXT:1;
+  // CHECK-FIXES-NEXT:}
+};
+
+void test_constexpr() {
+  constexpr_lambda_1();
+  constexpr_lambda_2();
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-braces-around-statements
+  ` check to
+  ignore false-positive for ``if constexpr`` in lambda expression.
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals.
Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -192,6 +192,9 @@
   while (const auto *AS = dyn_cast(S))
 S = AS->getSubStmt();
 
+  const SourceManager &SM = *Result.SourceManager;
+  const ASTContext *Context = Result.Context;
+
   // 1) If there's a corresponding "else" or "while", the check inserts "} "
   // right before that token.
   // 2) If there's a multi-line block comment starting on the same line after
@@ -204,10 +207,15 @@
 return false;
   }
 
+  // When TreeTransform, Stmt in constexpr IfStmt will be transform to 
NullStmt.
+  // This NullStmt can be detected according to beginning token.
+  const SourceLocation StmtBeginLoc = S->getBeginLoc();
+  if (isa(S) && StmtBeginLoc.isValid() &&
+  getTokenKind(StmtBeginLoc, SM, Context) == tok::l_brace)
+return false;
+
   if (!InitialLoc.isValid())
 return false;
-  const SourceManager &SM = *Result.SourceManager;
-  const ASTContext *Context = Result.Context;
 
   // Convert InitialLoc to file location, if it's on the same macro expansion
   // level as the start of the statement. We also need file locations for


Index: clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements.cpp
@@ -457,3 +457,25 @@
   // CHECK-FIXES-NEXT: }
 
 }
+
+template 
+auto constexpr_lambda_1 = [] {
+  if constexpr (A) {
+1;
+  }
+};
+
+template 
+auto constexpr_lambda_2 = [] {
+  // CHECK-MESSAGES: :[[@LINE+1]]:19: warning: statement should be inside braces
+  if constexpr (A)
+1;
+  // CHECK-FIXES:if constexpr (A) {
+  // CHECK-FIXES-NEXT:1;
+  // CHECK-FIXES-NEXT:}
+};
+
+void test_constexpr() {
+  constexpr_lambda_1();
+  constexpr_lambda_2();
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -228,6 +228,10 @@
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-braces-around-statements
+  ` check to
+  ignore false-positive for ``if constexpr`` in lambda expression.
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals.
Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/BracesAroundStatem

[PATCH] D151515: [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization

2023-09-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping @erichkeane


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151515/new/

https://reviews.llvm.org/D151515

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


[PATCH] D151515: [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization

2023-09-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 abandoned this revision.
HerrCai0907 added a comment.

https://github.com/llvm/llvm-project/pull/65918


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151515/new/

https://reviews.llvm.org/D151515

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505096.
HerrCai0907 added a comment.

add more testcase


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

Should I add release note in `clang/docs/ReleaseNotes.rst` or any other way?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505105.
HerrCai0907 added a comment.

add release note


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -170,6 +170,7 @@
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` 
statements
   previously issued from ``-Wunreachable-code`` and 
``-Wunreachable-code-fallthrough``
   by prioritizing ``-Wunreachable-code-fallthrough``.
+- Clang won't crash when fold expression contains a delayed typos correction.
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -170,6 +170,7 @@
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` statements
   previously issued from ``-Wunreachable-code`` and ``-Wunreachable-code-fallthrough``
   by prioritizing ``-Wunreachable-code-fallthrough``.
+- Clang won't crash when fold expression contains a delayed typos correction.
 
 Bug Fixes in This Version
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505111.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression contains a delayed typos correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression contains a delayed typos correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505122.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505126.
HerrCai0907 marked an inline comment as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505129.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
   (`#60405 `_)
 - Fix aggregate initialization inside lambda constexpr.
   (`#60936 `_)
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 505134.
HerrCai0907 added a comment.

rebase to main


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -197,6 +197,8 @@
   be reached despite being reachable. This fixes
   `#61177 `_ in anticipation
   of `CWG2699 _` being accepted by WG21.
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -197,6 +197,8 @@
   be reached despite being reachable. This fixes
   `#61177 `_ in anticipation
   of `CWG2699 _` being accepted by WG21.
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

I don't have write access now. Could you kindly help me to commit it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

HerrCai0907 and congcongcai0...@163.com

Thanks a lot!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

Hello Erichkeane, I have the access now, maybe I can push it by myself. Thanks 
again!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-14 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe417f02b5159: [SemaCXX]use CorrectDelayedTyposInExpr in 
ActOnCXXFoldExpr only when Diag (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains 
unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -197,6 +197,8 @@
   be reached despite being reachable. This fixes
   `#61177 `_ in anticipation
   of `CWG2699 _` being accepted by WG21.
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template  struct A {
+  template  void foo(T &&...Params) {
+foo((... + static_cast(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -197,6 +197,8 @@
   be reached despite being reachable. This fixes
   `#61177 `_ in anticipation
   of `CWG2699 _` being accepted by WG21.
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146885: [clang-tidy][NFC] add debug log when clean empty namespace

2023-03-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adding debug log when clean empty namespace can make 
(#60051)[https://github.com/llvm/llvm-project/issues/60051#issuecomment-1383923360]
 more cleaner.
User will not be confused why the whole namespace is deleted after fixing 
modernize-concat-nested-namespaces.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146885

Files:
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2472,10 +2472,13 @@
 
 for (auto Line : DeletedLines) {
   FormatToken *Tok = AnnotatedLines[Line]->First;
+  LLVM_DEBUG(llvm::dbgs() << "clean empty namespace:\"");
   while (Tok) {
+LLVM_DEBUG(llvm::dbgs() << Tok->TokenText << " ");
 deleteToken(Tok);
 Tok = Tok->Next;
   }
+  LLVM_DEBUG(llvm::dbgs() << "\"\n");
 }
   }
 


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2472,10 +2472,13 @@
 
 for (auto Line : DeletedLines) {
   FormatToken *Tok = AnnotatedLines[Line]->First;
+  LLVM_DEBUG(llvm::dbgs() << "clean empty namespace:\"");
   while (Tok) {
+LLVM_DEBUG(llvm::dbgs() << Tok->TokenText << " ");
 deleteToken(Tok);
 Tok = Tok->Next;
   }
+  LLVM_DEBUG(llvm::dbgs() << "\"\n");
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145834: typo statment to statement

2023-03-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: aaron.ballman.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

fix typo in some comments


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145834

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/Parse/ParseStmt.cpp


Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1100,7 +1100,7 @@
   ++LookAhead;
 }
 // Then look to see if the next two tokens close the statement expression;
-// if so, this expression statement is the last statement in a statment
+// if so, this expression statement is the last statement in a statement
 // expression.
 IsStmtExprResult = GetLookAheadToken(LookAhead).is(tok::r_brace) &&
GetLookAheadToken(LookAhead + 1).is(tok::r_paren);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -471,7 +471,7 @@
   const Expr *Value = CS->getLHS();
   PrimType ValueT = this->classifyPrim(Value->getType());
 
-  // Compare the case statment's value to the switch condition.
+  // Compare the case statement's value to the switch condition.
   if (!this->emitGetLocal(CondT, CondVar, CS))
 return false;
   if (!this->visit(Value))


Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1100,7 +1100,7 @@
   ++LookAhead;
 }
 // Then look to see if the next two tokens close the statement expression;
-// if so, this expression statement is the last statement in a statment
+// if so, this expression statement is the last statement in a statement
 // expression.
 IsStmtExprResult = GetLookAheadToken(LookAhead).is(tok::r_brace) &&
GetLookAheadToken(LookAhead + 1).is(tok::r_paren);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -471,7 +471,7 @@
   const Expr *Value = CS->getLHS();
   PrimType ValueT = this->classifyPrim(Value->getType());
 
-  // Compare the case statment's value to the switch condition.
+  // Compare the case statement's value to the switch condition.
   if (!this->emitGetLocal(CondT, CondVar, CS))
 return false;
   if (!this->visit(Value))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-12 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

PR #61326
CorrectDelayedTyposInExpr will clean all typo error and should only
happen when return invalid ExprResult


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145892

Files:
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded 
parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 
'Unknown'}}
+}
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template 
+void foo(T &&...Params) {
+  foo(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+  expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
-DiscardOperands();
-if (!Pack->containsUnexpandedParameterPack())
+if (!Pack->containsUnexpandedParameterPack()) {
+  DiscardOperands();
   return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();
+}
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145834: typo statment to statement

2023-03-13 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

Thanks, you can use my name HerrCai0907 (congcongcai0...@163.com) as patch 
attribution.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145834/new/

https://reviews.llvm.org/D145834

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-13 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

The idea is that:

1. If function return an invalid ExprResult, this error should be handled in 
the callee
2. If function return valid Expr, the potential error should be handled in the 
caller, in this case, is ActOnExprStmt. If callee handles error, when caller 
find some error and want to output error message, the error in this expression 
has been processed and cause crash.



> It seems this patch would make us miss other issues in the Foo(Unknown) if 
> they were to exist,

I try this code and it will not miss other issues

  c++
  template 
  void foo(T &&...Params) {
Unknown;
foo(Unknown);
((foo(Unknown + (10 / 0) + 10++)), ...);
  }



  build-demo/a.cpp:3:3: error: use of undeclared identifier 'Unknown'
Unknown;
^
  build-demo/a.cpp:4:3: error: expression contains unexpanded parameter pack 'T'
foo(Unknown);
^   ~
  build-demo/a.cpp:5:35: error: expression is not assignable
((foo(Unknown + (10 / 0) + 10++)), ...);
  ~~^
  build-demo/a.cpp:5:12: error: use of undeclared identifier 'Unknown'
((foo(Unknown + (10 / 0) + 10++)), ...);
 ^
  build-demo/a.cpp:5:26: warning: division by zero is undefined 
[-Wdivision-by-zero]
((foo(Unknown + (10 / 0) + 10++)), ...);
   ^ ~
  build-demo/a.cpp:4:10: error: use of undeclared identifier 'Unknown'
foo(Unknown);
   ^
  1 warning and 5 errors generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

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


[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

2023-03-13 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

I cannot find an example that throw `error: expression contains unexpanded 
parameter pack 'T'` in fold expression because code like ` (foo(10 + 
(static_cast(1))) + ...);` can be unpack both `T` and `U` in same `...` 
operator

But this code can be diagnosed correctly

  template  struct A {
template  void foo(T &&...Params) {
  (foo(1 + (static_cast(1))) + ...); // ok
  
  // error: expression contains unexpanded parameter pack 'T'
  foo((... + static_cast(1)));
  
  (foo((... + static_cast(1))) + ...); // ok
}
  };

Should I add this case into test?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

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


[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-03-29 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

remove each namespace except the last non-nest namespace,
replace the last non-nest namespace with the new name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -156,6 +156,20 @@
 } // namespace n41
 // CHECK-FIXES: }
 
+
+namespace n43 {
+// CHECK-MESSAGES-DAG: :[[@LINE-1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: }
+// CHECK-FIXES: #undef N43_INNER
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn2
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -29,8 +29,8 @@
   using NamespaceContextVec = llvm::SmallVector;
   using NamespaceString = llvm::SmallString<40>;
 
-  void reportDiagnostic(const SourceRange &FrontReplacement,
-const SourceRange &BackReplacement);
+  void reportDiagnostic(const SourceManager &Sources,
+const LangOptions &LangOpts);
   NamespaceString concatNamespaces();
   NamespaceContextVec Namespaces;
 };
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -9,8 +9,10 @@
 #include "ConcatNestedNamespacesCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
 #include 
+#include 
 
 namespace clang::tidy::modernize {
 
@@ -20,6 +22,13 @@
  Sources.getFileID(Loc1) == Sources.getFileID(Loc2);
 }
 
+static StringRef getRawStringRef(const SourceRange &Range,
+ const SourceManager &Sources,
+ const LangOptions &LangOpts) {
+  CharSourceRange TextRange = Lexer::getAsCharRange(Range, Sources, LangOpts);
+  return Lexer::getSourceText(TextRange, Sources, LangOpts);
+}
+
 static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
   return ND.isAnonymousNamespace() || ND.isInlineNamespace();
 }
@@ -38,11 +47,66 @@
 const SourceManager &Sources,
 const LangOptions &LangOpts) {
   // FIXME: This logic breaks when there is a comment with ':'s in the middle.
-  CharSourceRange TextRange =
-  Lexer::getAsCharRange(ReplacementRange, Sources, LangOpts);
-  StringRef CurrentNamespacesText =
-  Lexer::getSourceText(TextRange, Sources, LangOpts);
-  return CurrentNamespacesText.count(':') == (NumCandidates - 1) * 2;
+  return getRawStringRef(ReplacementRange, Sources, LangOpts).count(':') ==
+ (NumCandidates - 1) * 2;
+}
+
+static std::optional findNextToken(SourceLocation Loc,
+  const SourceManager &SM,
+  const LangOptions &LangOpts,
+  bool WithCommen

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-03-30 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp:70
+  File.data() + LocInfo.second, File.end());
+  L.SetCommentRetentionState(WithComment);
+  // Find the token.

This part of code copy from `Lexer::findNextToken` except this line. Should I 
refactor `Lexer::findNextToken` for example add a parameter to control it?
But `Lexer::findNextToken` is involved with lots of code. Maybe use another 
patch to do it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

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


[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-03-30 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 marked 3 inline comments as done.
HerrCai0907 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp:49
 const LangOptions &LangOpts) {
   // FIXME: This logic breaks when there is a comment with ':'s in the middle.
+  return getRawStringRef(ReplacementRange, Sources, LangOpts).count(':') ==

PiotrZSL wrote:
> check if you can do something with this...
> 
> add test for:
> 
> with something like:
> ```
> namespace x1 {
> // namespace x3::x4 {
> namespace x2 {
> void foo();
> }
> // }
> }
> ```
> 
It still have false negative.
But this should be done in another PR. In here I just extract a common function 
without changing the logic.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

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


[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-03-30 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 509860.
HerrCai0907 marked an inline comment as done.
HerrCai0907 added a comment.

refactor some code and add release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -156,6 +156,20 @@
 } // namespace n41
 // CHECK-FIXES: }
 
+
+namespace n43 {
+// CHECK-MESSAGES-DAG: :[[@LINE-1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: }
+// CHECK-FIXES: #undef N43_INNER
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn2
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -261,6 +261,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed an issue in :doc:`modernize-concat-nested-namespaces
+  ` when using macro between 
+  namespace declarations could result incorrect fix.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -85,6 +85,10 @@
   }
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
+   const LangOptions &LangOpts);
+
 // Finds next token that's not a comment.
 std::optional findNextTokenSkippingComments(SourceLocation Start,
const SourceManager &SM,
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -75,6 +75,29 @@
   return findNextAnyTokenKind(Start, SM, LangOpts, tok::comma, tok::semi);
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  // `Lexer::findNextToken` will ignore comment
+  if (Start.isMacroID())
+return std::nullopt;
+  Start = Lexer::getLocForEndOfToken(Start, 0, SM, LangOpts);
+  // Break down the source location.
+  std::pair LocInfo = SM.getDecomposedLoc(Start);
+  bool InvalidTemp = false;
+  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
+  if (InvalidTemp)
+return std::nullopt;
+  // Lex from the start of the given location.
+  Lexer L(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
+  File.data() + LocInfo.second, File.end());
+  L.SetCommentRetentionState(true);
+  // Find the token.
+  Token Tok;
+  L.LexFromRawLexer(Tok);
+  return Tok;
+}
+
 std::optional
 findNextTokenSkippingComments(SourceLocation Start, const SourceManager &SM,
   const LangOptions &LangOpts) {
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -29,8 +29,8 @@
   using NamespaceContextV

[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-03-31 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: LegalizeAdulthood.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

fixed 60810 
add matcher for `enumConstantDecl`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147315

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -1,10 +1,21 @@
 // RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/static-accessed-through-instance
 #include <__clang_cuda_builtin_vars.h>
 
+enum OutEnum {
+  E0,
+};
+
 struct C {
   static void foo();
   static int x;
   int nsx;
+  enum {
+Anonymous,
+  };
+  enum E {
+E1,
+  };
+  using enum OutEnum;
   void mf() {
 (void)&x;// OK, x is accessed inside the struct.
 (void)&C::x; // OK, x is accessed using a qualified-id.
@@ -144,6 +155,16 @@
   c1->x; // 2
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
   // CHECK-FIXES: {{^}}  C::x; // 2{{$}}
+  c1->Anonymous; // 3
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::Anonymous; // 3{{$}}
+  c1->E1; // 4
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E1; // 4{{$}}
+  c1->E0; // 5
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E0; // 5{{$}}
+
   c1->nsx; // OK, nsx is a non-static member.
 
   const C *c2 = new C();
Index: clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
@@ -15,11 +15,15 @@
   struct C {
 static void foo();
 static int x;
+enum { E1 };
+enum E { E2 };
   };
 
   C *c1 = new C();
   c1->foo();
   c1->x;
+  c1->E1;
+  c1->E2;
 
 is changed to:
 
@@ -28,4 +32,6 @@
   C *c1 = new C();
   C::foo();
   C::x;
+  C::E1;
+  C::E2;
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -261,6 +261,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to 
+  support unscoped enumerations through instances.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -39,7 +39,8 @@
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
-  varDecl(hasStaticStorageDuration()
+  varDecl(hasStaticStorageDuration()),
+  enumConstantDecl(
   .bind("memberExpression"),
   this);
 }
@@ -64,15 +65,15 @@
   : BaseExpr->getType().getUnqualifiedType();
 
   const ASTContext *AstContext = Result.Context;
-  PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
-  PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
-  PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+  PrintingPolicy PrintingPolicyWithSuppressedTag(AstContext->getLangOpts());
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
-  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes =
   !BaseExpr->getType()->isTypedefNameType();
 
   std::string BaseTypeName =
-  BaseType.getAsString(PrintingPolicyWithSupressedTag);
+  BaseType.getAsString(P

[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-03-31 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

In D147315#4236403 , @PiotrZSL wrote:

> Add test with scoped enums, to validate that it works correctly.
> In theory this change should suport them also.

scoped enum not support to visit by member. `EnumName::` is needed for scoped 
enum. And `ins.EnumName` is invalid.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147315/new/

https://reviews.llvm.org/D147315

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-01 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 510241.
HerrCai0907 added a comment.

update description


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147315/new/

https://reviews.llvm.org/D147315

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -1,10 +1,21 @@
 // RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/static-accessed-through-instance
 #include <__clang_cuda_builtin_vars.h>
 
+enum OutEnum {
+  E0,
+};
+
 struct C {
   static void foo();
   static int x;
   int nsx;
+  enum {
+Anonymous,
+  };
+  enum E {
+E1,
+  };
+  using enum OutEnum;
   void mf() {
 (void)&x;// OK, x is accessed inside the struct.
 (void)&C::x; // OK, x is accessed using a qualified-id.
@@ -144,6 +155,16 @@
   c1->x; // 2
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
   // CHECK-FIXES: {{^}}  C::x; // 2{{$}}
+  c1->Anonymous; // 3
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::Anonymous; // 3{{$}}
+  c1->E1; // 4
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E1; // 4{{$}}
+  c1->E0; // 5
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E0; // 5{{$}}
+
   c1->nsx; // OK, nsx is a non-static member.
 
   const C *c2 = new C();
Index: clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
@@ -15,11 +15,15 @@
   struct C {
 static void foo();
 static int x;
+enum { E1 };
+enum E { E2 };
   };
 
   C *c1 = new C();
   c1->foo();
   c1->x;
+  c1->E1;
+  c1->E2;
 
 is changed to:
 
@@ -28,4 +32,6 @@
   C *c1 = new C();
   C::foo();
   C::x;
+  C::E1;
+  C::E2;
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -244,6 +244,10 @@
   ` check when warning would
   be unnecessarily emitted for template dependent ``if constexpr``.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to 
+  support unscoped enumerations through instances.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -39,7 +39,8 @@
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
-  varDecl(hasStaticStorageDuration()
+  varDecl(hasStaticStorageDuration()),
+  enumConstantDecl(
   .bind("memberExpression"),
   this);
 }
@@ -64,15 +65,15 @@
   : BaseExpr->getType().getUnqualifiedType();
 
   const ASTContext *AstContext = Result.Context;
-  PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
-  PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
-  PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+  PrintingPolicy PrintingPolicyWithSuppressedTag(AstContext->getLangOpts());
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
-  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes =
   !BaseExpr->getType()->isTypedefNameType();
 
   std::string BaseTypeName =
-  BaseType.getAsString(PrintingPolicyWithSupressedTag);
+  BaseType.getAsString(PrintingPolicyWithSuppressedTag);
 
   // Do not warn for CUDA built-in variables.
   if (StringRef(BaseType

[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-01 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

In D147315#4238596 , @carlosgalvezp 
wrote:

> Would it make sense to add a scoped enum to the test, to ensure it doesn't 
> warn/fix?

It is not possible to visit scoped enum by instance. I think adding an invalid 
expression to test it is meaningless.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147315/new/

https://reviews.llvm.org/D147315

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-03 Thread Congcong Cai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGedd6a33984ee: [clang-tidy] support unscoped enumerations in 
readability-static-accessed… (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147315/new/

https://reviews.llvm.org/D147315

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -1,10 +1,21 @@
 // RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/static-accessed-through-instance
 #include <__clang_cuda_builtin_vars.h>
 
+enum OutEnum {
+  E0,
+};
+
 struct C {
   static void foo();
   static int x;
   int nsx;
+  enum {
+Anonymous,
+  };
+  enum E {
+E1,
+  };
+  using enum OutEnum;
   void mf() {
 (void)&x;// OK, x is accessed inside the struct.
 (void)&C::x; // OK, x is accessed using a qualified-id.
@@ -144,6 +155,16 @@
   c1->x; // 2
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
   // CHECK-FIXES: {{^}}  C::x; // 2{{$}}
+  c1->Anonymous; // 3
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::Anonymous; // 3{{$}}
+  c1->E1; // 4
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E1; // 4{{$}}
+  c1->E0; // 5
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E0; // 5{{$}}
+
   c1->nsx; // OK, nsx is a non-static member.
 
   const C *c2 = new C();
Index: clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
@@ -15,11 +15,15 @@
   struct C {
 static void foo();
 static int x;
+enum { E1 };
+enum E { E2 };
   };
 
   C *c1 = new C();
   c1->foo();
   c1->x;
+  c1->E1;
+  c1->E2;
 
 is changed to:
 
@@ -28,4 +32,6 @@
   C *c1 = new C();
   C::foo();
   C::x;
+  C::E1;
+  C::E2;
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -254,6 +254,10 @@
   ` check when warning would
   be unnecessarily emitted for template dependent ``if constexpr``.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to 
+  support unscoped enumerations through instances.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -39,7 +39,8 @@
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
-  varDecl(hasStaticStorageDuration()
+  varDecl(hasStaticStorageDuration()),
+  enumConstantDecl(
   .bind("memberExpression"),
   this);
 }
@@ -64,15 +65,15 @@
   : BaseExpr->getType().getUnqualifiedType();
 
   const ASTContext *AstContext = Result.Context;
-  PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
-  PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
-  PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+  PrintingPolicy PrintingPolicyWithSuppressedTag(AstContext->getLangOpts());
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
-  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes =
   !BaseExpr->getType()->isTypedefNameType();
 
   std::string BaseTypeName =
-  BaseType.getAsString(PrintingPolicyWithSupressedTag);
+  BaseType.getAsStrin

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-04-03 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 510658.
HerrCai0907 edited the summary of this revision.
HerrCai0907 added a comment.

add feature update close comment in fixhint
update acc. comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -143,7 +143,7 @@
 #endif
 } // namespace n40
 } // namespace n39
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n39::n40
 
 namespace n41 {
 namespace n42 {
@@ -154,7 +154,50 @@
 #endif
 } // namespace n42
 } // namespace n41
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n41::n42
+
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n43 {
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: } // namespace n43::n44
+// CHECK-FIXES: #undef N43_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n45{
+#define N45_INNER
+namespace n46
+{
+#pragma clang diagnostic push
+namespace n47 {
+void foo() {}
+} // namespace n47
+#pragma clang diagnostic pop
+} //namespace n46
+#undef N45_INNER
+} //namespace n45
+// CHECK-FIXES: #define N45_INNER
+// CHECK-FIXES: #pragma clang diagnostic push
+// CHECK-FIXES: namespace n45::n46::n47 {
+// CHECK-FIXES: } // namespace n45::n46::n47
+// CHECK-FIXES: #pragma clang diagnostic pop
+// CHECK-FIXES: #undef N45_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_add_close_comment {
+namespace inner {
+void foo() {}
+}
+}
+// CHECK-FIXES: namespace avoid_add_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
 int main() {
   n26::n27::n28::n29::n30::t();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn1::nn2
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -275,6 +275,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed an issue in :doc:`modernize-concat-nested-namespaces
+  ` when using macro between 
+  namespace declarations could result incorrect fix.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -85,6 +85,10 @@
   }
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
+   const LangOptions &LangOpts);
+
 // Finds next token that's not a comment.
 std::optional findNextTokenSkippingComments(SourceLocation Start,
const SourceManager &SM,
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -75,6 +75,29 @@
   return findNextAnyTokenKind(Start, SM, LangOpts, tok::comma, tok::semi);
 }
 
+std::optional

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-04-07 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 511757.
HerrCai0907 added a comment.
Herald added a subscriber: ChuanqiXu.

update according to comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -143,7 +143,7 @@
 #endif
 } // namespace n40
 } // namespace n39
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n39::n40
 
 namespace n41 {
 namespace n42 {
@@ -154,7 +154,59 @@
 #endif
 } // namespace n42
 } // namespace n41
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n41::n42
+
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n43 {
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: } // namespace n43::n44
+// CHECK-FIXES: #undef N43_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n45{
+#define N45_INNER
+namespace n46
+{
+#pragma clang diagnostic push
+namespace n47 {
+void foo() {}
+} // namespace n47
+#pragma clang diagnostic pop
+} //namespace n46
+#undef N45_INNER
+} //namespace n45
+// CHECK-FIXES: #define N45_INNER
+// CHECK-FIXES: #pragma clang diagnostic push
+// CHECK-FIXES: namespace n45::n46::n47 {
+// CHECK-FIXES: } // namespace n45::n46::n47
+// CHECK-FIXES: #pragma clang diagnostic pop
+// CHECK-FIXES: #undef N45_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_add_close_comment {
+namespace inner {
+void foo() {}
+}
+}
+// CHECK-FIXES: namespace avoid_add_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_change_close_comment {
+namespace inner {
+void foo() {}
+} // namespace inner and other comments
+} // namespace avoid_change_close_comment and other comments
+// CHECK-FIXES: namespace avoid_change_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
 int main() {
   n26::n27::n28::n29::n30::t();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn1::nn2
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed an issue in :doc:`modernize-concat-nested-namespaces
+  ` when using macro between 
+  namespace declarations could result incorrect fix.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -85,6 +85,10 @@
   }
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
+   const LangOptions &LangOpts);
+
 // Finds next token that's not a comment.
 std::optional findNextTokenSkippingComments(SourceLocation Start,
   

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-04-07 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 511763.
HerrCai0907 marked 4 inline comments as done.
HerrCai0907 added a comment.

reorder fixhint


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -143,7 +143,7 @@
 #endif
 } // namespace n40
 } // namespace n39
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n39::n40
 
 namespace n41 {
 namespace n42 {
@@ -154,7 +154,59 @@
 #endif
 } // namespace n42
 } // namespace n41
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n41::n42
+
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n43 {
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: } // namespace n43::n44
+// CHECK-FIXES: #undef N43_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n45{
+#define N45_INNER
+namespace n46
+{
+#pragma clang diagnostic push
+namespace n47 {
+void foo() {}
+} // namespace n47
+#pragma clang diagnostic pop
+} //namespace n46
+#undef N45_INNER
+} //namespace n45
+// CHECK-FIXES: #define N45_INNER
+// CHECK-FIXES: #pragma clang diagnostic push
+// CHECK-FIXES: namespace n45::n46::n47 {
+// CHECK-FIXES: } // namespace n45::n46::n47
+// CHECK-FIXES: #pragma clang diagnostic pop
+// CHECK-FIXES: #undef N45_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_add_close_comment {
+namespace inner {
+void foo() {}
+}
+}
+// CHECK-FIXES: namespace avoid_add_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_change_close_comment {
+namespace inner {
+void foo() {}
+} // namespace inner and other comments
+} // namespace avoid_change_close_comment and other comments
+// CHECK-FIXES: namespace avoid_change_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
 int main() {
   n26::n27::n28::n29::n30::t();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn1::nn2
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed an issue in :doc:`modernize-concat-nested-namespaces
+  ` when using macro between 
+  namespace declarations could result incorrect fix.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -85,6 +85,10 @@
   }
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
+   const LangOptions &LangOpts);
+
 // Finds next token that's not a comment.
 std::optional findNextTokenSkippingComments(SourceLocation Start,
   

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-04-07 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 marked 2 inline comments as done.
HerrCai0907 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp:88
+  StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
+  if (TokText != "// namespace " + ND->getNameAsString())
+return DefaultSourceRange;

PiotrZSL wrote:
> PiotrZSL wrote:
> > what if it is //namespace ? or /* namespace XYZ */
> ok, but it still can be things like `//   namespace XYZ`
> So instead adding single space, consider using some trim/strip.
> but thats minor issues, side effect would be just an leftover namespace 
> comment.
> add some test with something like `// namespace XYZ - closing namespace` to 
> verify that some custom comments wont be removed, and make sure that 
> documentation mention this, that we remove only namespace comments that 
> follow some known standard.
> 
> you could also check for:
> ```
> namespace C
> {
> } // C
> ```
I think it can cover most of scenarios. It don't worth to introduce a mechanism 
to archive it.
Because something false positive like // name space XYZ should also be 
considered.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

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


[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-04-07 Thread Congcong Cai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92910a51b904: [clang-tidy] fix concat-nest-namespace fix 
hint remove the macro (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147194/new/

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -143,7 +143,7 @@
 #endif
 } // namespace n40
 } // namespace n39
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n39::n40
 
 namespace n41 {
 namespace n42 {
@@ -154,7 +154,59 @@
 #endif
 } // namespace n42
 } // namespace n41
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n41::n42
+
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n43 {
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: } // namespace n43::n44
+// CHECK-FIXES: #undef N43_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n45{
+#define N45_INNER
+namespace n46
+{
+#pragma clang diagnostic push
+namespace n47 {
+void foo() {}
+} // namespace n47
+#pragma clang diagnostic pop
+} //namespace n46
+#undef N45_INNER
+} //namespace n45
+// CHECK-FIXES: #define N45_INNER
+// CHECK-FIXES: #pragma clang diagnostic push
+// CHECK-FIXES: namespace n45::n46::n47 {
+// CHECK-FIXES: } // namespace n45::n46::n47
+// CHECK-FIXES: #pragma clang diagnostic pop
+// CHECK-FIXES: #undef N45_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_add_close_comment {
+namespace inner {
+void foo() {}
+}
+}
+// CHECK-FIXES: namespace avoid_add_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_change_close_comment {
+namespace inner {
+void foo() {}
+} // namespace inner and other comments
+} // namespace avoid_change_close_comment and other comments
+// CHECK-FIXES: namespace avoid_change_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
 int main() {
   n26::n27::n28::n29::n30::t();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn1::nn2
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed an issue in :doc:`modernize-concat-nested-namespaces
+  ` when using macro between 
+  namespace declarations could result incorrect fix.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -85,6 +85,10 @@
   }
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
+   const LangOptions &LangOpts);
+
 // Finds next token that's not a comment.
 std::optional findNextTokenSkippingComments(SourceLo

[PATCH] D147843: [clang-tidy] fix hint use correct range to replace last NamespaceDecl

2023-04-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

range of replacing last namespace decl should be from last non nested namespace 
to last namespace


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147843

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -105,7 +105,7 @@
 namespace n28 {
 namespace n29::n30 {
 // CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n26::n27::n28::n29::n30
+// CHECK-FIXES: namespace n26::n27::n28::n29::n30 {
 void t() {}
 } // namespace n29::n30
 } // namespace n28
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -124,12 +124,12 @@
   SmallVector Backs;
   Backs.reserve(Namespaces.size());
 
-  NamespaceDecl const *LastND = nullptr;
+  NamespaceDecl const *LastNonNestND = nullptr;
 
   for (const NamespaceDecl *ND : Namespaces) {
 if (ND->isNested())
   continue;
-LastND = ND;
+LastNonNestND = ND;
 std::optional SR =
 getCleanedNamespaceFrontRange(ND, SM, LangOpts);
 if (!SR.has_value())
@@ -137,7 +137,7 @@
 Fronts.push_back(SR.value());
 Backs.push_back(getCleanedNamespaceBackRange(ND, SM, LangOpts));
   }
-  if (LastND == nullptr || Fronts.empty() || Backs.empty())
+  if (LastNonNestND == nullptr || Fronts.empty() || Backs.empty())
 return;
   // the last one should be handled specially
   Fronts.pop_back();
@@ -147,9 +147,11 @@
   for (SourceRange const &Front : Fronts)
 DB << FixItHint::CreateRemoval(Front);
   DB << FixItHint::CreateReplacement(
-  SourceRange{LastND->getBeginLoc(), LastND->getLocation()},
+  SourceRange{LastNonNestND->getBeginLoc(),
+  Namespaces.back()->getLocation()},
   ConcatNameSpace);
-  if (LastRBrace != SourceRange{LastND->getRBraceLoc(), 
LastND->getRBraceLoc()})
+  if (LastRBrace !=
+  SourceRange{LastNonNestND->getRBraceLoc(), 
LastNonNestND->getRBraceLoc()})
 DB << FixItHint::CreateReplacement(LastRBrace,
("} // " + ConcatNameSpace).str());
   for (SourceRange const &Back : llvm::reverse(Backs))


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -105,7 +105,7 @@
 namespace n28 {
 namespace n29::n30 {
 // CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n26::n27::n28::n29::n30
+// CHECK-FIXES: namespace n26::n27::n28::n29::n30 {
 void t() {}
 } // namespace n29::n30
 } // namespace n28
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -124,12 +124,12 @@
   SmallVector Backs;
   Backs.reserve(Namespaces.size());
 
-  NamespaceDecl const *LastND = nullptr;
+  NamespaceDecl const *LastNonNestND = nullptr;
 
   for (const NamespaceDecl *ND : Namespaces) {
 if (ND->isNested())
   continue;
-LastND = ND;
+LastNonNestND = ND;
 std::optional SR =
 getCleanedNamespaceFrontRange(ND, SM, LangOpts);
 if (!SR.has_value())
@@ -137,7 +137,7 @@
 Fronts.push_back(SR.value());
 Backs.push_back(getCleanedNamespaceBackRange(ND, SM, LangOpts));
   }
-  if (LastND == nullptr || Fronts.empty() || Backs.empty())
+  if (LastNonNestND == nullptr || Fronts.empty() || Backs.empty())
 return;
   // the last one should be handled specially
   Fronts.pop_back();
@@ -147,9 +147,11 @@
   for (SourceRange const &Front : Fronts)
 DB << FixItHint::CreateRemoval(Front);
   DB << FixItHint::CreateReplacement(
-  SourceRa

[PATCH] D147843: [clang-tidy] fix hint use correct range to replace last NamespaceDecl

2023-04-08 Thread Congcong Cai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f9b71d11b91: [clang-tidy] fix hint use correct range to 
replace last NamespaceDecl (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147843/new/

https://reviews.llvm.org/D147843

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -105,7 +105,7 @@
 namespace n28 {
 namespace n29::n30 {
 // CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n26::n27::n28::n29::n30
+// CHECK-FIXES: namespace n26::n27::n28::n29::n30 {
 void t() {}
 } // namespace n29::n30
 } // namespace n28
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -124,12 +124,12 @@
   SmallVector Backs;
   Backs.reserve(Namespaces.size());
 
-  NamespaceDecl const *LastND = nullptr;
+  NamespaceDecl const *LastNonNestND = nullptr;
 
   for (const NamespaceDecl *ND : Namespaces) {
 if (ND->isNested())
   continue;
-LastND = ND;
+LastNonNestND = ND;
 std::optional SR =
 getCleanedNamespaceFrontRange(ND, SM, LangOpts);
 if (!SR.has_value())
@@ -137,7 +137,7 @@
 Fronts.push_back(SR.value());
 Backs.push_back(getCleanedNamespaceBackRange(ND, SM, LangOpts));
   }
-  if (LastND == nullptr || Fronts.empty() || Backs.empty())
+  if (LastNonNestND == nullptr || Fronts.empty() || Backs.empty())
 return;
   // the last one should be handled specially
   Fronts.pop_back();
@@ -147,9 +147,11 @@
   for (SourceRange const &Front : Fronts)
 DB << FixItHint::CreateRemoval(Front);
   DB << FixItHint::CreateReplacement(
-  SourceRange{LastND->getBeginLoc(), LastND->getLocation()},
+  SourceRange{LastNonNestND->getBeginLoc(),
+  Namespaces.back()->getLocation()},
   ConcatNameSpace);
-  if (LastRBrace != SourceRange{LastND->getRBraceLoc(), 
LastND->getRBraceLoc()})
+  if (LastRBrace !=
+  SourceRange{LastNonNestND->getRBraceLoc(), 
LastNonNestND->getRBraceLoc()})
 DB << FixItHint::CreateReplacement(LastRBrace,
("} // " + ConcatNameSpace).str());
   for (SourceRange const &Back : llvm::reverse(Backs))


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -105,7 +105,7 @@
 namespace n28 {
 namespace n29::n30 {
 // CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n26::n27::n28::n29::n30
+// CHECK-FIXES: namespace n26::n27::n28::n29::n30 {
 void t() {}
 } // namespace n29::n30
 } // namespace n28
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -124,12 +124,12 @@
   SmallVector Backs;
   Backs.reserve(Namespaces.size());
 
-  NamespaceDecl const *LastND = nullptr;
+  NamespaceDecl const *LastNonNestND = nullptr;
 
   for (const NamespaceDecl *ND : Namespaces) {
 if (ND->isNested())
   continue;
-LastND = ND;
+LastNonNestND = ND;
 std::optional SR =
 getCleanedNamespaceFrontRange(ND, SM, LangOpts);
 if (!SR.has_value())
@@ -137,7 +137,7 @@
 Fronts.push_back(SR.value());
 Backs.push_back(getCleanedNamespaceBackRange(ND, SM, LangOpts));
   }
-  if (LastND == nullptr || Fronts.empty() || Backs.empty())
+  if (LastNonNestND == nullptr || Fronts.empty() || Backs.empty())
 return;
   // the last one should be handled specially
   Fronts.pop_back();
@@ -147,9 +147,11 @@
   for (SourceRange const &Front : Fronts)
 DB << FixItHint::CreateRemoval(Front);
   DB << FixItHint::CreateReplacement(
-  SourceRange{LastND->getBeginLoc(), LastND->getLocation()},
+  SourceRange{LastNonNestND->getBeginLoc(),
+  Namespaces.back()->getLocation(

[PATCH] D147857: [clang-tidy] fix false positve for namespace with attrs in modernize-concat-nested-namespaces

2023-04-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

add pre check to avoid false positive for namespace with attributes like

  namespace [[deprecated]] ns {}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147857

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -21,11 +21,17 @@
 } // namespace n2
 
 namespace n5 {
-inline namespace n6 {
+inline namespace inline_ns {
 void t();
-}
+} // namespace inline_ns
 } // namespace n5
 
+namespace n6 {
+namespace [[deprecated]] attr_ns {
+void t();
+} // namespace attr_ns
+} // namespace n6
+
 namespace n7 {
 void t();
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -305,6 +305,10 @@
   ` when using macro 
between
   namespace declarations could result incorrect fix.
 
+- Fixed an false positive in :doc:`modernize-concat-nested-namespaces
+  ` when using namespace 
with 
+  attributes.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -31,8 +31,9 @@
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
-static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
-  return ND.isAnonymousNamespace() || ND.isInlineNamespace();
+static bool unsupportedNamespace(const NamespaceDecl &ND) {
+  return ND.isAnonymousNamespace() || ND.isInlineNamespace() ||
+ !ND.attrs().empty();
 }
 
 static bool singleNamedNamespaceChild(const NamespaceDecl &ND) {
@@ -41,7 +42,7 @@
 return false;
 
   const auto *ChildNamespace = dyn_cast(*Decls.begin());
-  return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace);
+  return ChildNamespace && !unsupportedNamespace(*ChildNamespace);
 }
 
 static bool alreadyConcatenated(std::size_t NumCandidates,
@@ -166,7 +167,7 @@
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
 
-  if (anonymousOrInlineNamespace(ND))
+  if (unsupportedNamespace(ND))
 return;
 
   Namespaces.push_back(&ND);


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -21,11 +21,17 @@
 } // namespace n2
 
 namespace n5 {
-inline namespace n6 {
+inline namespace inline_ns {
 void t();
-}
+} // namespace inline_ns
 } // namespace n5
 
+namespace n6 {
+namespace [[deprecated]] attr_ns {
+void t();
+} // namespace attr_ns
+} // namespace n6
+
 namespace n7 {
 void t();
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -305,6 +305,10 @@
   ` when using macro between
   namespace declarations could result incorrect fix.
 
+- Fixed an false positive in :doc:`modernize-concat-nested-namespaces
+  ` when using namespace with 
+  attributes.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -31,8 +31,9 @@
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
-static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
-  return ND.isAnonymousNamespace() || ND.isInlineNamespace();
+static bool unsupportedNamespace(const NamespaceDec

[PATCH] D147857: [clang-tidy] fix false positve for namespace with attrs in modernize-concat-nested-namespaces

2023-04-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

It should fix https://github.com/llvm/llvm-project/issues/57530 due to side 
effect instead of root cause.\


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147857/new/

https://reviews.llvm.org/D147857

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


[PATCH] D147857: [clang-tidy] fix false positve for namespace with attrs in modernize-concat-nested-namespaces

2023-04-09 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 512004.
HerrCai0907 edited the summary of this revision.
HerrCai0907 added a comment.

merge items in release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147857/new/

https://reviews.llvm.org/D147857

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -21,11 +21,17 @@
 } // namespace n2
 
 namespace n5 {
-inline namespace n6 {
+inline namespace inline_ns {
 void t();
-}
+} // namespace inline_ns
 } // namespace n5
 
+namespace n6 {
+namespace [[deprecated]] attr_ns {
+void t();
+} // namespace attr_ns
+} // namespace n6
+
 namespace n7 {
 void t();
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -301,9 +301,10 @@
   ` 
when using
   ``DISABLED_`` in the test suite name.
 
-- Fixed an issue in :doc:`modernize-concat-nested-namespaces
-  ` when using macro 
between
-  namespace declarations could result incorrect fix.
+- Improved :doc:`modernize-concat-nested-namespaces
+  ` to fix incorrect 
fixes when 
+  using macro between namespace declarations and false positive when using 
namespace 
+  with attributes.
 
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -31,8 +31,9 @@
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
-static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
-  return ND.isAnonymousNamespace() || ND.isInlineNamespace();
+static bool unsupportedNamespace(const NamespaceDecl &ND) {
+  return ND.isAnonymousNamespace() || ND.isInlineNamespace() ||
+ !ND.attrs().empty();
 }
 
 static bool singleNamedNamespaceChild(const NamespaceDecl &ND) {
@@ -41,7 +42,7 @@
 return false;
 
   const auto *ChildNamespace = dyn_cast(*Decls.begin());
-  return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace);
+  return ChildNamespace && !unsupportedNamespace(*ChildNamespace);
 }
 
 static bool alreadyConcatenated(std::size_t NumCandidates,
@@ -166,7 +167,7 @@
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
 
-  if (anonymousOrInlineNamespace(ND))
+  if (unsupportedNamespace(ND))
 return;
 
   Namespaces.push_back(&ND);


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -21,11 +21,17 @@
 } // namespace n2
 
 namespace n5 {
-inline namespace n6 {
+inline namespace inline_ns {
 void t();
-}
+} // namespace inline_ns
 } // namespace n5
 
+namespace n6 {
+namespace [[deprecated]] attr_ns {
+void t();
+} // namespace attr_ns
+} // namespace n6
+
 namespace n7 {
 void t();
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -301,9 +301,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
-- Fixed an issue in :doc:`modernize-concat-nested-namespaces
-  ` when using macro between
-  namespace declarations could result incorrect fix.
+- Improved :doc:`modernize-concat-nested-namespaces
+  ` to fix incorrect fixes when 
+  using macro between namespace declarations and false positive when using namespace 
+  with attributes.
 
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -31,8 +31,9 @@
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
-static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
-  return ND.isAnonymousNamespace() || ND.isInlineNamesp

[PATCH] D147857: [clang-tidy] fix false positve for namespace with attrs in modernize-concat-nested-namespaces

2023-04-09 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbdf7fd8297bc: [clang-tidy] fix false positve for namespace 
with attrs in modernize-concat… (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147857/new/

https://reviews.llvm.org/D147857

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -21,11 +21,17 @@
 } // namespace n2
 
 namespace n5 {
-inline namespace n6 {
+inline namespace inline_ns {
 void t();
-}
+} // namespace inline_ns
 } // namespace n5
 
+namespace n6 {
+namespace [[deprecated]] attr_ns {
+void t();
+} // namespace attr_ns
+} // namespace n6
+
 namespace n7 {
 void t();
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -301,9 +301,10 @@
   ` 
when using
   ``DISABLED_`` in the test suite name.
 
-- Fixed an issue in :doc:`modernize-concat-nested-namespaces
-  ` when using macro 
between
-  namespace declarations could result incorrect fix.
+- Improved :doc:`modernize-concat-nested-namespaces
+  ` to fix incorrect 
fixes when 
+  using macro between namespace declarations and false positive when using 
namespace 
+  with attributes.
 
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -31,8 +31,9 @@
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
-static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
-  return ND.isAnonymousNamespace() || ND.isInlineNamespace();
+static bool unsupportedNamespace(const NamespaceDecl &ND) {
+  return ND.isAnonymousNamespace() || ND.isInlineNamespace() ||
+ !ND.attrs().empty();
 }
 
 static bool singleNamedNamespaceChild(const NamespaceDecl &ND) {
@@ -41,7 +42,7 @@
 return false;
 
   const auto *ChildNamespace = dyn_cast(*Decls.begin());
-  return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace);
+  return ChildNamespace && !unsupportedNamespace(*ChildNamespace);
 }
 
 static bool alreadyConcatenated(std::size_t NumCandidates,
@@ -166,7 +167,7 @@
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
 
-  if (anonymousOrInlineNamespace(ND))
+  if (unsupportedNamespace(ND))
 return;
 
   Namespaces.push_back(&ND);


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -21,11 +21,17 @@
 } // namespace n2
 
 namespace n5 {
-inline namespace n6 {
+inline namespace inline_ns {
 void t();
-}
+} // namespace inline_ns
 } // namespace n5
 
+namespace n6 {
+namespace [[deprecated]] attr_ns {
+void t();
+} // namespace attr_ns
+} // namespace n6
+
 namespace n7 {
 void t();
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -301,9 +301,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
-- Fixed an issue in :doc:`modernize-concat-nested-namespaces
-  ` when using macro between
-  namespace declarations could result incorrect fix.
+- Improved :doc:`modernize-concat-nested-namespaces
+  ` to fix incorrect fixes when 
+  using macro between namespace declarations and false positive when using namespace 
+  with attributes.
 
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -31,8 +31,9 @@
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
-static bool 

[PATCH] D147893: [clang-tidy] avoid colon in namespace cause false positve

2023-04-09 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Refactor the Namespaces with NamespaceDecl[][].
First level stores non nested namepsace.
Second level stores nested namespace.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147893

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -214,6 +214,18 @@
 // CHECK-FIXES: namespace avoid_change_close_comment::inner {
 // CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
+namespace /*::*/ comment_colon_1 {
+void foo() {}
+} // namespace comment_colon_1
+// CHECK-FIXES: namespace /*::*/ comment_colon_1 {
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace /*::*/ comment_colon_2 {
+namespace comment_colon_2 {
+void foo() {}
+} // namespace comment_colon_2
+} // namespace comment_colon_2
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -15,6 +15,20 @@
 
 namespace clang::tidy::modernize {
 
+using NamespaceName = llvm::SmallString<40>;
+
+class NS : public llvm::SmallVector {
+public:
+  std::optional
+  getCleanedNamespaceFrontRange(const SourceManager &SM,
+const LangOptions &LangOpts) const;
+  SourceRange getReplacedNamespaceFrontRange() const;
+  SourceRange getNamespaceBackRange(const SourceManager &SM,
+const LangOptions &LangOpts) const;
+  SourceRange getDefaultNamespaceBackRange() const;
+  NamespaceName getName() const;
+};
+
 class ConcatNestedNamespacesCheck : public ClangTidyCheck {
 public:
   ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context)
@@ -26,12 +40,10 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
-  using NamespaceContextVec = llvm::SmallVector;
-  using NamespaceString = llvm::SmallString<40>;
+  using NamespaceContextVec = llvm::SmallVector;
 
   void reportDiagnostic(const SourceManager &Sources,
 const LangOptions &LangOpts);
-  NamespaceString concatNamespaces();
   NamespaceContextVec Namespaces;
 };
 } // namespace clang::tidy::modernize
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -12,7 +12,6 @@
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/STLExtras.h"
 #include 
 #include 
 
@@ -45,22 +44,23 @@
   return ChildNamespace && !unsupportedNamespace(*ChildNamespace);
 }
 
-static bool alreadyConcatenated(std::size_t NumCandidates,
-const SourceRange &ReplacementRange,
-const SourceManager &Sources,
-const LangOptions &LangOpts) {
-  // FIXME: This logic breaks when there is a comment with ':'s in the middle.
-  return getRawStringRef(ReplacementRange, Sources, LangOpts).count(':') ==
- (NumCandidates - 1) * 2;
+template 
+static void concatNamespace(NamespaceName &ConcatNameSpace, R &&Range,
+F &&Stringify) {
+  for (auto const &V : Range) {
+ConcatNameSpace.append(Stringify(V));
+if (V != Range.back())
+  ConcatNameSpace.append("::");
+  }
 }
 
-static std::optional
-getCleanedNamespaceFrontRange(const NamespaceDecl *ND, const SourceManager &SM,
-  const LangOptions &LangOpts) {
+std::optional
+NS::getCleanedNamespaceFrontRange(const SourceManager &SM,
+  const LangOptions &LangOpts) const {
   // Front from namespace tp '{'
   std::optional Tok =
   ::clang::tidy::utils::lexer::findNextTokenSkippingComments(
-  ND->getLocation(), SM, La

[PATCH] D147893: [clang-tidy] avoid colon in namespace cause false positve

2023-04-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 512116.
HerrCai0907 added a comment.

remove debug log


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147893/new/

https://reviews.llvm.org/D147893

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -214,6 +214,18 @@
 // CHECK-FIXES: namespace avoid_change_close_comment::inner {
 // CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
+namespace /*::*/ comment_colon_1 {
+void foo() {}
+} // namespace comment_colon_1
+// CHECK-FIXES: namespace /*::*/ comment_colon_1 {
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace /*::*/ comment_colon_2 {
+namespace comment_colon_2 {
+void foo() {}
+} // namespace comment_colon_2
+} // namespace comment_colon_2
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -15,6 +15,20 @@
 
 namespace clang::tidy::modernize {
 
+using NamespaceName = llvm::SmallString<40>;
+
+class NS : public llvm::SmallVector {
+public:
+  std::optional
+  getCleanedNamespaceFrontRange(const SourceManager &SM,
+const LangOptions &LangOpts) const;
+  SourceRange getReplacedNamespaceFrontRange() const;
+  SourceRange getNamespaceBackRange(const SourceManager &SM,
+const LangOptions &LangOpts) const;
+  SourceRange getDefaultNamespaceBackRange() const;
+  NamespaceName getName() const;
+};
+
 class ConcatNestedNamespacesCheck : public ClangTidyCheck {
 public:
   ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context)
@@ -26,12 +40,10 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
-  using NamespaceContextVec = llvm::SmallVector;
-  using NamespaceString = llvm::SmallString<40>;
+  using NamespaceContextVec = llvm::SmallVector;
 
   void reportDiagnostic(const SourceManager &Sources,
 const LangOptions &LangOpts);
-  NamespaceString concatNamespaces();
   NamespaceContextVec Namespaces;
 };
 } // namespace clang::tidy::modernize
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -12,7 +12,6 @@
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/STLExtras.h"
 #include 
 #include 
 
@@ -45,22 +44,23 @@
   return ChildNamespace && !unsupportedNamespace(*ChildNamespace);
 }
 
-static bool alreadyConcatenated(std::size_t NumCandidates,
-const SourceRange &ReplacementRange,
-const SourceManager &Sources,
-const LangOptions &LangOpts) {
-  // FIXME: This logic breaks when there is a comment with ':'s in the middle.
-  return getRawStringRef(ReplacementRange, Sources, LangOpts).count(':') ==
- (NumCandidates - 1) * 2;
+template 
+static void concatNamespace(NamespaceName &ConcatNameSpace, R &&Range,
+F &&Stringify) {
+  for (auto const &V : Range) {
+ConcatNameSpace.append(Stringify(V));
+if (V != Range.back())
+  ConcatNameSpace.append("::");
+  }
 }
 
-static std::optional
-getCleanedNamespaceFrontRange(const NamespaceDecl *ND, const SourceManager &SM,
-  const LangOptions &LangOpts) {
+std::optional
+NS::getCleanedNamespaceFrontRange(const SourceManager &SM,
+  const LangOptions &LangOpts) const {
   // Front from namespace tp '{'
   std::optional Tok =
   ::clang::tidy::utils::lexer::findNextTokenSkippingComments(
-  ND->getLocation(), SM, LangOpts);
+  back()->getLocation(), SM, LangOpts);
   if (!Tok)
 return std::nullopt;
   while (Tok->getKind() != tok::TokenKind::l_brace) {
@@ -69,44 +69,40 @@
 if (!Tok)
   return std::nullopt;
   }
-  return SourceRange{ND->getBeginLoc(), Tok->getEndLoc()};
+  re

[PATCH] D147893: [clang-tidy] avoid colon in namespace cause false positve

2023-04-10 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72777dc000ac: [clang-tidy] avoid colon in namespace cause 
false positve (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147893/new/

https://reviews.llvm.org/D147893

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -214,6 +214,18 @@
 // CHECK-FIXES: namespace avoid_change_close_comment::inner {
 // CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
+namespace /*::*/ comment_colon_1 {
+void foo() {}
+} // namespace comment_colon_1
+// CHECK-FIXES: namespace /*::*/ comment_colon_1 {
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace /*::*/ comment_colon_2 {
+namespace comment_colon_2 {
+void foo() {}
+} // namespace comment_colon_2
+} // namespace comment_colon_2
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -15,6 +15,20 @@
 
 namespace clang::tidy::modernize {
 
+using NamespaceName = llvm::SmallString<40>;
+
+class NS : public llvm::SmallVector {
+public:
+  std::optional
+  getCleanedNamespaceFrontRange(const SourceManager &SM,
+const LangOptions &LangOpts) const;
+  SourceRange getReplacedNamespaceFrontRange() const;
+  SourceRange getNamespaceBackRange(const SourceManager &SM,
+const LangOptions &LangOpts) const;
+  SourceRange getDefaultNamespaceBackRange() const;
+  NamespaceName getName() const;
+};
+
 class ConcatNestedNamespacesCheck : public ClangTidyCheck {
 public:
   ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context)
@@ -26,12 +40,10 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
-  using NamespaceContextVec = llvm::SmallVector;
-  using NamespaceString = llvm::SmallString<40>;
+  using NamespaceContextVec = llvm::SmallVector;
 
   void reportDiagnostic(const SourceManager &Sources,
 const LangOptions &LangOpts);
-  NamespaceString concatNamespaces();
   NamespaceContextVec Namespaces;
 };
 } // namespace clang::tidy::modernize
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -12,7 +12,6 @@
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/STLExtras.h"
 #include 
 #include 
 
@@ -45,22 +44,23 @@
   return ChildNamespace && !unsupportedNamespace(*ChildNamespace);
 }
 
-static bool alreadyConcatenated(std::size_t NumCandidates,
-const SourceRange &ReplacementRange,
-const SourceManager &Sources,
-const LangOptions &LangOpts) {
-  // FIXME: This logic breaks when there is a comment with ':'s in the middle.
-  return getRawStringRef(ReplacementRange, Sources, LangOpts).count(':') ==
- (NumCandidates - 1) * 2;
+template 
+static void concatNamespace(NamespaceName &ConcatNameSpace, R &&Range,
+F &&Stringify) {
+  for (auto const &V : Range) {
+ConcatNameSpace.append(Stringify(V));
+if (V != Range.back())
+  ConcatNameSpace.append("::");
+  }
 }
 
-static std::optional
-getCleanedNamespaceFrontRange(const NamespaceDecl *ND, const SourceManager &SM,
-  const LangOptions &LangOpts) {
+std::optional
+NS::getCleanedNamespaceFrontRange(const SourceManager &SM,
+  const LangOptions &LangOpts) const {
   // Front from namespace tp '{'
   std::optional Tok =
   ::clang::tidy::utils::lexer::findNextTokenSkippingComments(
-  ND->getLocation(), SM, LangOpts);
+  back()->getLocation(), SM, LangOpts);
   if (!Tok)
 return std::nullopt;
   while (Tok->getKind() != tok::Toke

[PATCH] D147946: [clang-tidy] support inline namespace in c++20

2023-04-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixed https://github.com/llvm/llvm-project/issues/56022
c++20 support namespace like `namespace a::inline b {}`.
If an inline namespace is not the first, it can be concatened.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147946

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -1,14 +1,11 @@
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 // Restore header file and re-run with c++20:
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 
-#include "modernize-concat-nested-namespaces.h"
-// CHECK-MESSAGES-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-
 namespace n1 {}
 
 namespace n2 {
@@ -20,12 +17,6 @@
 }
 } // namespace n2
 
-namespace n5 {
-inline namespace inline_ns {
-void t();
-} // namespace inline_ns
-} // namespace n5
-
 namespace n6 {
 namespace [[deprecated]] attr_ns {
 void t();
@@ -42,17 +33,17 @@
 
 namespace n9 {
 namespace n10 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n9::n10
+// CHECK-MESSAGES-NORMAL: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n9::n10
 void t();
 } // namespace n10
 } // namespace n9
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n11 {
 namespace n12 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n11::n12
+// CHECK-MESSAGES-NORMAL: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n11::n12
 namespace n13 {
 void t();
 }
@@ -61,7 +52,7 @@
 }
 } // namespace n12
 } // namespace n11
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n15 {
 namespace n16 {
@@ -75,13 +66,13 @@
 namespace n18 {
 namespace n19 {
 namespace n20 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n18::n19::n20
+// CHECK-MESSAGES-NORMAL: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n18::n19::n20
 void t();
 } // namespace n20
 } // namespace n19
 } // namespace n18
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n21 {
 void t();
@@ -98,38 +89,36 @@
 namespace {
 namespace n24 {
 namespace n25 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n24::n25
+// CHECK-MESSAGES-NORMAL: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n24::n25
 void t();
 } // namespace n25
 } // namespace n24
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 } // namespace
 } // namespace n23
 
 namespace n26::n27 {
 namespace n28 

[PATCH] D147946: [clang-tidy] support nested inline namespace in c++20 for modernize-concat-nested-namespaces

2023-04-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 512165.
HerrCai0907 added a comment.

remove lamda


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147946/new/

https://reviews.llvm.org/D147946

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -1,14 +1,11 @@
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 // Restore header file and re-run with c++20:
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 
-#include "modernize-concat-nested-namespaces.h"
-// CHECK-MESSAGES-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-
 namespace n1 {}
 
 namespace n2 {
@@ -20,12 +17,6 @@
 }
 } // namespace n2
 
-namespace n5 {
-inline namespace inline_ns {
-void t();
-} // namespace inline_ns
-} // namespace n5
-
 namespace n6 {
 namespace [[deprecated]] attr_ns {
 void t();
@@ -42,17 +33,17 @@
 
 namespace n9 {
 namespace n10 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n9::n10
+// CHECK-MESSAGES-NORMAL: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n9::n10
 void t();
 } // namespace n10
 } // namespace n9
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n11 {
 namespace n12 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n11::n12
+// CHECK-MESSAGES-NORMAL: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n11::n12
 namespace n13 {
 void t();
 }
@@ -61,7 +52,7 @@
 }
 } // namespace n12
 } // namespace n11
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n15 {
 namespace n16 {
@@ -75,13 +66,13 @@
 namespace n18 {
 namespace n19 {
 namespace n20 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n18::n19::n20
+// CHECK-MESSAGES-NORMAL: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n18::n19::n20
 void t();
 } // namespace n20
 } // namespace n19
 } // namespace n18
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n21 {
 void t();
@@ -98,38 +89,36 @@
 namespace {
 namespace n24 {
 namespace n25 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n24::n25
+// CHECK-MESSAGES-NORMAL: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n24::n25
 void t();
 } // namespace n25
 } // namespace n24
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 } // namespace
 } // namespace n23
 
 namespace n26::n27 {
 namespace n28 {
 namespace n29::n30 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n26::n27::n28::n29::n30 {
+// CHECK-MESSAGES-NORMAL: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-

[PATCH] D147946: [clang-tidy] support nested inline namespace in c++20 for modernize-concat-nested-namespaces

2023-04-10 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 512231.
HerrCai0907 added a comment.

fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147946/new/

https://reviews.llvm.org/D147946

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -1,13 +1,13 @@
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 // Restore header file and re-run with c++20:
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 
 #include "modernize-concat-nested-namespaces.h"
-// CHECK-MESSAGES-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES-NORMAL-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
 
 namespace n1 {}
 
@@ -20,12 +20,6 @@
 }
 } // namespace n2
 
-namespace n5 {
-inline namespace inline_ns {
-void t();
-} // namespace inline_ns
-} // namespace n5
-
 namespace n6 {
 namespace [[deprecated]] attr_ns {
 void t();
@@ -42,17 +36,17 @@
 
 namespace n9 {
 namespace n10 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n9::n10
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n9::n10
 void t();
 } // namespace n10
 } // namespace n9
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n11 {
 namespace n12 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n11::n12
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n11::n12
 namespace n13 {
 void t();
 }
@@ -61,7 +55,7 @@
 }
 } // namespace n12
 } // namespace n11
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n15 {
 namespace n16 {
@@ -75,13 +69,13 @@
 namespace n18 {
 namespace n19 {
 namespace n20 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n18::n19::n20
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n18::n19::n20
 void t();
 } // namespace n20
 } // namespace n19
 } // namespace n18
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n21 {
 void t();
@@ -98,38 +92,36 @@
 namespace {
 namespace n24 {
 namespace n25 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n24::n25
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n24::n25
 void t();
 } // namespace n25
 } // namespace n24
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 } // namespace
 } // namespace n23
 
 namespace n26::n27 {
 namespace n28 {
 namespace n29::n30 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n26::n27::

[PATCH] D147946: [clang-tidy] support nested inline namespace in c++20 for modernize-concat-nested-namespaces

2023-04-11 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 512541.
HerrCai0907 added a comment.

update acc. comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147946/new/

https://reviews.llvm.org/D147946

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -1,13 +1,13 @@
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 // Restore header file and re-run with c++20:
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 
 #include "modernize-concat-nested-namespaces.h"
-// CHECK-MESSAGES-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES-NORMAL-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
 
 namespace n1 {}
 
@@ -20,12 +20,6 @@
 }
 } // namespace n2
 
-namespace n5 {
-inline namespace inline_ns {
-void t();
-} // namespace inline_ns
-} // namespace n5
-
 namespace n6 {
 namespace [[deprecated]] attr_ns {
 void t();
@@ -42,17 +36,17 @@
 
 namespace n9 {
 namespace n10 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n9::n10
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n9::n10
 void t();
 } // namespace n10
 } // namespace n9
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n11 {
 namespace n12 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n11::n12
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n11::n12
 namespace n13 {
 void t();
 }
@@ -61,7 +55,7 @@
 }
 } // namespace n12
 } // namespace n11
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n15 {
 namespace n16 {
@@ -75,13 +69,13 @@
 namespace n18 {
 namespace n19 {
 namespace n20 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n18::n19::n20
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n18::n19::n20
 void t();
 } // namespace n20
 } // namespace n19
 } // namespace n18
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n21 {
 void t();
@@ -98,38 +92,36 @@
 namespace {
 namespace n24 {
 namespace n25 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n24::n25
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n24::n25
 void t();
 } // namespace n25
 } // namespace n24
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 } // namespace
 } // namespace n23
 
 namespace n26::n27 {
 namespace n28 {
 namespace n29::n30 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespac

[PATCH] D147946: [clang-tidy] support nested inline namespace in c++20 for modernize-concat-nested-namespaces

2023-04-11 Thread Congcong Cai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32aaacc609e7: [clang-tidy] support nested inline namespace 
in c++20 for modernize-concat… (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147946/new/

https://reviews.llvm.org/D147946

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -1,13 +1,13 @@
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 // Restore header file and re-run with c++20:
 // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
-// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: %check_clang_tidy -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
 // RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
 
 #include "modernize-concat-nested-namespaces.h"
-// CHECK-MESSAGES-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES-NORMAL-DAG: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
 
 namespace n1 {}
 
@@ -20,12 +20,6 @@
 }
 } // namespace n2
 
-namespace n5 {
-inline namespace inline_ns {
-void t();
-} // namespace inline_ns
-} // namespace n5
-
 namespace n6 {
 namespace [[deprecated]] attr_ns {
 void t();
@@ -42,17 +36,17 @@
 
 namespace n9 {
 namespace n10 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n9::n10
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n9::n10
 void t();
 } // namespace n10
 } // namespace n9
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n11 {
 namespace n12 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n11::n12
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n11::n12
 namespace n13 {
 void t();
 }
@@ -61,7 +55,7 @@
 }
 } // namespace n12
 } // namespace n11
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n15 {
 namespace n16 {
@@ -75,13 +69,13 @@
 namespace n18 {
 namespace n19 {
 namespace n20 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n18::n19::n20
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n18::n19::n20
 void t();
 } // namespace n20
 } // namespace n19
 } // namespace n18
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 
 namespace n21 {
 void t();
@@ -98,38 +92,36 @@
 namespace {
 namespace n24 {
 namespace n25 {
-// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
-// CHECK-FIXES: namespace n24::n25
+// CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES-NORMAL: namespace n24::n25
 void t();
 } // namespace n25
 } // namespace n24
-// CHECK-FIXES: }
+// CHECK-FIXES-NORMAL: }
 } // namespace
 } // namespace n23
 
 namespace n26::n27 {
 namespace n28 {
 namespace n29::n30 {
-// CHECK-MESSAGES-DAG: :[[@LINE-3]]:1: 

[PATCH] D148372: [clang] add diagnose when member function contains invalid default argument

2023-04-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added reviewers: aaron.ballman, cjdb.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62122
This change pointer to add diagnose message for this code.

  struct S {
  static int F(int n = 0 ? 0) {
  return 0;
  }
  };

The old code only marks the Decl invalid without emiting diagnoise.
It will miss some error and crash CodeGen step.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148372

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/cxx-member-initializers.cpp


Index: clang/test/Parser/cxx-member-initializers.cpp
===
--- clang/test/Parser/cxx-member-initializers.cpp
+++ clang/test/Parser/cxx-member-initializers.cpp
@@ -108,4 +108,6 @@
   // expected-error@-2 {{type name requires a specifier or qualifier}}
   // expected-error@-3 {{expected '>'}}
   // expected-note@-4 {{to match this '<'}}
+
+  void n(int x = 1 ? 2) {} // expected-error {{expected initializer}}
 };
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7383,6 +7383,7 @@
   SourceLocation ArgStartLoc = NextToken().getLocation();
   if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
 DefArgToks.reset();
+Diag(ArgStartLoc, diag::err_expected) << "initializer";
 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
   } else {
 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 `_)
+- Fix crash when member function contains invalid default argument.
+  (`#62122 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Parser/cxx-member-initializers.cpp
===
--- clang/test/Parser/cxx-member-initializers.cpp
+++ clang/test/Parser/cxx-member-initializers.cpp
@@ -108,4 +108,6 @@
   // expected-error@-2 {{type name requires a specifier or qualifier}}
   // expected-error@-3 {{expected '>'}}
   // expected-note@-4 {{to match this '<'}}
+
+  void n(int x = 1 ? 2) {} // expected-error {{expected initializer}}
 };
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7383,6 +7383,7 @@
   SourceLocation ArgStartLoc = NextToken().getLocation();
   if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
 DefArgToks.reset();
+Diag(ArgStartLoc, diag::err_expected) << "initializer";
 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
   } else {
 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 `_)
+- Fix crash when member function contains invalid default argument.
+  (`#62122 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148372: [clang] add diagnose when member function contains invalid default argument

2023-04-14 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

> While this will fix the crash I am a little concerned that I don't a 
> diagnostic for each place we call ActOnParamDefaultArgumentError(...), there 
> is only once place where we diagnose this the rest don't. So I wonder if this 
> was purposeful or not.

No, before `ActOnParamDefaultArgumentError` we either call `Diag`  or use 
`Actions.CorrectDelayedTyposInExpr` to diagnoise except here. And the coverage 
report shows that this is not covered by any test code[1]. So I guess it miss 
something.

> We are not actually diagnosing the main problem which is a malformed 
> conditional expression.

I also want to diagnose main problem. Should I emit diagnose in 
`ConsumeAndStoreInitializer` directly (control by a bool argument e.g. 
`IsDiag`)?

[1] 
https://lab.llvm.org/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Parse/ParseDecl.cpp.html#L7388


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148372/new/

https://reviews.llvm.org/D148372

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-19 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 523870.
HerrCai0907 added a comment.

revert untill first version


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/merge-decls.c


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int 
(*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 
'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 
'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || 
New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -383,6 +383,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` `_)
 - Fix the assertion hit when generating code for global variable initializer of


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -383,6 +383,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` `_)
 - Fix the assertion hit when generating code for global variable initializer of
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-19 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-20 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524001.
HerrCai0907 added a comment.

simplify test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/merge-decls.c


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int 
(*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char test8_gh62447[d.undef == 8]; // expected-error {{member reference base 
type 'char' is not a structure or union}}
+char test8_gh62447[d.undef == 4]; // expected-error {{member reference base 
type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || 
New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -383,6 +383,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` `_)
 - Fix the assertion hit when generating code for global variable initializer of


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char test8_gh62447[d.undef == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char test8_gh62447[d.undef == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -383,6 +383,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` `_)
 - Fix the assertion hit when generating code for global variable initializer of
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-20 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

@rsmith could you review it again?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-20 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef107afd48a9: [Sema] avoid merge error type (authored by 
HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/merge-decls.c


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int 
(*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char test8_gh62447[d.undef == 8]; // expected-error {{member reference base 
type 'char' is not a structure or union}}
+char test8_gh62447[d.undef == 4]; // expected-error {{member reference base 
type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || 
New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -392,6 +392,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` `_)
 - Fix the assertion hit when generating code for global variable initializer of


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char test8_gh62447[d.undef == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char test8_gh62447[d.undef == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -392,6 +392,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` `_)
 - Fix the assertion hit when generating code for global variable initializer of
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524582.
HerrCai0907 added a comment.

update comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.getName().get

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb5902ffc971: [Sema] `setInvalidDecl` for error deduction 
declaration (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ 

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 reopened this revision.
HerrCai0907 added a comment.
This revision is now accepted and ready to land.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

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


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524824.
HerrCai0907 added a comment.

add std option


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.ge

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524849.
HerrCai0907 added a comment.

format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.getName().

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca9683651e52: [Sema] `setInvalidDecl` for error deduction 
declaration (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction =

[PATCH] D151365: [Sema] cast to CXXRecoradDecl correctly when diag a default comparison method

2023-05-24 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62791
in c++20, default comparison is supported. `getLexicalDeclContext` maybe cannot
get the `CXXRecord` if default comparison defined out of `CXXRecord`.
This patch want to visit all the declaration of error function and find the
correct `CXXRecord`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151365

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,17 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
-Diags.Report(Active->PointOfInstantiation,
- diag::note_comparison_synthesized_at)
-<< (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+CXXRecordDecl *RD = nullptr;
+for (Decl *D : FD->redecls()) {
+  RD = dyn_cast(D->getLexicalDeclContext());
+  if (RD)
+break;
+}
+if (RD)
+  Diags.Report(Active->PointOfInstantiation,
+  diag::note_comparison_synthesized_at)
+  << (int)DFK.asComparison()
+  << Context.getTagDeclType(RD);
   }
   break;
 }


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,17 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
-Diags.Report(Active->PointOfInstantiation,
- diag::note_comparison_synthesized_at)
-<< (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclCon

[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-24 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

In D151365#4369605 , @erichkeane 
wrote:

> As Richard says, we should just be taking the first parameter type and using 
> that instead (obviously de-qualified and removing reference if necessary).

But we still can find the correctly RecordDecl by `redecls`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

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


[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-24 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 525333.
HerrCai0907 added a comment.

change solution


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,13 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType = FD->getParamDecl(0)
+  ->getType()
+  .getNonReferenceType();
 Diags.Report(Active->PointOfInstantiation,
  diag::note_comparison_synthesized_at)
 << (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< Context.getRecordType(RecordType->getAsRecordDecl());
   }
   break;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -439,6 +439,9 @@
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+- Fix crash when diagnosing default comparison method.
+  (`#62791 `_) and
+  (`#62102 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,13 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType = FD->get

[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-24 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 525452.
HerrCai0907 added a comment.

format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,12 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType =
+FD->getParamDecl(0)->getType().getNonReferenceType();
 Diags.Report(Active->PointOfInstantiation,
  diag::note_comparison_synthesized_at)
 << (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< Context.getRecordType(RecordType->getAsRecordDecl());
   }
   break;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -439,6 +439,9 @@
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+- Fix crash when diagnosing default comparison method.
+  (`#62791 `_) and
+  (`#62102 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,12 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType =
+FD->getParamDecl(0)->getType().getNonReferenceType();

[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 525718.
HerrCai0907 added a comment.
Herald added subscribers: pmatos, asb, aheejin, jgravelle-google, sbc100, 
dschuff.

getLocallyUnqualifiedSingleStepDesugaredType to find the whole record name


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,14 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType =
+FD->getParamDecl(0)
+->getType()
+.getNonReferenceType()
+->getLocallyUnqualifiedSingleStepDesugaredType();
 Diags.Report(Active->PointOfInstantiation,
  diag::note_comparison_synthesized_at)
-<< (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< (int)DFK.asComparison() << RecordType;
   }
   break;
 }
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -163,6 +163,7 @@
 bool WebAssemblyTargetInfo::handleTargetFeatures(
 std::vector &Features, DiagnosticsEngine &Diags) {
   for (const auto &Feature : Features) {
+llvm::errs() << Feature << "\n";
 if (Feature == "+simd128") {
   SIMDLevel = std::max(SIMDLevel, SIMD128);
   continue;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -439,6 +439,9 @@
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+- Fix crash when diagnosing default comparison method.
+  (`#62791 `_) and
+  (`#62102 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defa

[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:969
 << (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< Context.getRecordType(RecordType->getAsRecordDecl());
   }

erichkeane wrote:
> What is going on here?  You already have the `RecordType` in the RecordType 
> variable.  You don't need to go to RecordDecl and back?  You should just be 
> able to put the `RecordType` variable directly.  
I am not very familiar with QualType's conversion. Do you think it is the 
correct path to remove all qualifier and get the full name for class?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

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


[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 525752.
HerrCai0907 added a comment.

avoid desurger


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
+++ clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
@@ -227,5 +227,5 @@
 A a;
 std::strong_ordering operator<=>(const B&) const = default; // 
expected-error {{call to deleted constructor of 'A'}}
   };
-  bool x = B() < B(); // expected-note {{in defaulted three-way comparison 
operator for 'Preference::B' first required here}}
+  bool x = B() < B(); // expected-note {{in defaulted three-way comparison 
operator for 'B' first required here}}
 }
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,13 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType = FD->getParamDecl(0)
+  ->getType()
+  .getNonReferenceType()
+  .getUnqualifiedType();
 Diags.Report(Active->PointOfInstantiation,
  diag::note_comparison_synthesized_at)
-<< (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< (int)DFK.asComparison() << RecordType;
   }
   break;
 }
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -163,6 +163,7 @@
 bool WebAssemblyTargetInfo::handleTargetFeatures(
 std::vector &Features, DiagnosticsEngine &Diags) {
   for (const auto &Feature : Features) {
+llvm::errs() << Feature << "\n";
 if (Feature == "+simd128") {
   SIMDLevel = std::max(SIMDLevel, SIMD128);
   continue;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -439,6 +439,9 @@
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+- Fix crash when diagnosing default comparison method.
+  (`#62791 `_) and
+  (`#62102 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// 

[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 525754.
HerrCai0907 added a comment.

remove not related change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
+++ clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
@@ -227,5 +227,5 @@
 A a;
 std::strong_ordering operator<=>(const B&) const = default; // 
expected-error {{call to deleted constructor of 'A'}}
   };
-  bool x = B() < B(); // expected-note {{in defaulted three-way comparison 
operator for 'Preference::B' first required here}}
+  bool x = B() < B(); // expected-note {{in defaulted three-way comparison 
operator for 'B' first required here}}
 }
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,13 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType = FD->getParamDecl(0)
+  ->getType()
+  .getNonReferenceType()
+  .getUnqualifiedType();
 Diags.Report(Active->PointOfInstantiation,
  diag::note_comparison_synthesized_at)
-<< (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< (int)DFK.asComparison() << RecordType;
   }
   break;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -439,6 +439,9 @@
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+- Fix crash when diagnosing default comparison method.
+  (`#62791 `_) and
+  (`#62102 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator fo

[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

2023-05-25 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5df593a35471: [Sema] cast to CXXRecordDecl correctly when 
diag a default comparison method (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/SemaCXX/cxx20-default-compare.cpp


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo &, const Foo &) = default;  // expected-warning 
{{comparing floating point with == or != is unsafe}} expected-note {{in 
defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
+bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
Index: clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
+++ clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
@@ -227,5 +227,5 @@
 A a;
 std::strong_ordering operator<=>(const B&) const = default; // 
expected-error {{call to deleted constructor of 'A'}}
   };
-  bool x = B() < B(); // expected-note {{in defaulted three-way comparison 
operator for 'Preference::B' first required here}}
+  bool x = B() < B(); // expected-note {{in defaulted three-way comparison 
operator for 'B' first required here}}
 }
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -961,11 +961,13 @@
 << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
 << Context.getTagDeclType(MD->getParent());
   } else if (DFK.isComparison()) {
+QualType RecordType = FD->getParamDecl(0)
+  ->getType()
+  .getNonReferenceType()
+  .getUnqualifiedType();
 Diags.Report(Active->PointOfInstantiation,
  diag::note_comparison_synthesized_at)
-<< (int)DFK.asComparison()
-<< Context.getTagDeclType(
-   cast(FD->getLexicalDeclContext()));
+<< (int)DFK.asComparison() << RecordType;
   }
   break;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -445,6 +445,9 @@
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+- Fix crash when diagnosing default comparison method.
+  (`#62791 `_) and
+  (`#62102 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx20-default-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
+
+struct Foo {
+  float val;
+  bool operator==(const Foo &) const;
+  friend bool operator==(const Foo &, const Foo &);
+  friend bool operator==(Foo, Foo );
+};
+
+// Declare the defaulted comparison function as a member function.
+bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}
+
+// Declare the defaulted comparison function as a non-member function.
+bool operator==(const Foo 

[PATCH] D151515: [CodeGen] add additional cast when checking call arguments

2023-05-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added reviewers: shafik, erichkeane, aaron.ballman.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62945
c++20 supports "Permit conversions to arrays of unknown bound".
This make it possible that ConstantArrayType is function parameter
but IncompleteArrayType is argument (initializer list).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151515

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp


Index: clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
===
--- clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4369,14 +4369,19 @@
 CallExpr::const_arg_iterator Arg = ArgRange.begin();
 for (QualType Ty : ArgTypes) {
   assert(Arg != ArgRange.end() && "Running over edge of argument list!");
-  assert(
-  (isGenericMethod || Ty->isVariablyModifiedType() ||
-   Ty.getNonReferenceType()->isObjCRetainableType() ||
-   getContext()
-   .getCanonicalType(Ty.getNonReferenceType())
-   .getTypePtr() ==
-   getContext().getCanonicalType((*Arg)->getType()).getTypePtr()) 
&&
-  "type mismatch in call argument!");
+  // argument can be ConstantArrayType and parameter can be 
IncompleteArrayType
+  const Type *CanonicalTy = getContext()
+.getCanonicalType(Ty.getNonReferenceType())
+.getTypePtr()
+->getPointeeOrArrayElementType();
+  const Type *CanonicalArgTy = getContext()
+   .getCanonicalType((*Arg)->getType())
+   .getTypePtr()
+   ->getPointeeOrArrayElementType();
+  assert((isGenericMethod || Ty->isVariablyModifiedType() ||
+  Ty.getNonReferenceType()->isObjCRetainableType() ||
+  CanonicalTy == CanonicalArgTy) &&
+ "type mismatch in call argument!");
   ++Arg;
 }
 


Index: clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
===
--- clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4369,14 +4369,19 @@
 CallExpr::const_arg_iterator Arg = ArgRange.begin();
 for (QualType Ty : ArgTypes) {
   assert(Arg != ArgRange.end() && "Running over edge of argument list!");
-  assert(
-  (isGenericMethod || Ty->isVariablyModifiedType() ||
-   Ty.getNonReferenceType()->isObjCRetainableType() ||
-   getContext()
-   .getCanonicalType(Ty.getNonReferenceType())
-   .getTypePtr() ==
-   getContext().getCanonicalType((*Arg)->getType()).getTypePtr()) &&
-  "type mismatch in call argument!");
+  // argument can be ConstantArrayType and parameter can be IncompleteArrayType
+  const Type *CanonicalTy = getContext()
+.getCanonicalType(Ty.getNonReferenceType())
+.getTypePtr()
+->getPointeeOrArrayElementType();
+  const Type *CanonicalArgTy = getContext()
+   .getCanonicalType((*Arg)->getType())
+   .getTypePtr()
+   ->getPointeeOrArrayElementType();
+  assert((isGenericMethod || Ty->isVariablyModifiedType() ||
+  Ty.getNonReferenceType()->isObjCRetainableType() ||
+  CanonicalTy == CanonicalArgTy) &&
+ "type mismatch in call argument!");
   ++Arg;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151515: [CodeGen] add additional cast when checking call arguments

2023-05-26 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 526245.
HerrCai0907 added a comment.

add cast


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151515/new/

https://reviews.llvm.org/D151515

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp


Index: clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
===
--- clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4423,6 +4423,15 @@
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }
 } else
   Sequence.SetFailed(
   
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);


Index: clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
===
--- clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4423,6 +4423,15 @@
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }
 } else
   Sequence.SetFailed(
   InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151515: [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization

2023-05-30 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4433
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }

erichkeane wrote:
> Is `VK_XValue` correct here?  The standards quote says it is a PRValue?
The original text of standards in https://eel.is/c++draft/dcl.init.list is 
> List-initialization of an object or reference of type T is defined as follows:

> 3.10 Otherwise, if T is a reference type, a prvalue is generated. The prvalue 
> initializes its result object by copy-list-initialization from the 
> initializer list. The prvalue is then used to direct-initialize the 
> reference. The type of the prvalue is the type referenced by T, unless T is 
> “reference to array of unknown bound of U”, in which case the type of the 
> prvalue is the type of x in the declaration U x[] H, where H is the 
> initializer list.

My understand is that a PRValue is generated by XValue initialization list.

By the way, I have try to use VK_PRValue, it cause the assert failed:
can't implicitly cast glvalue to prvalue with this cast kind: NoOp 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151515/new/

https://reviews.llvm.org/D151515

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


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-04 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping @rsmith


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-04 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

Dependent type for CPP is a common case due to template. But for `mergeTypes` 
in C,  dependent type cannot be handled correctly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-04 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 519671.
HerrCai0907 added a comment.

getConstantArrayType instal QualType()


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/merge-decls.c


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int 
(*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 
'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 
'char' is not a structure or union}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2579,7 +2579,13 @@
   T = Context.getIncompleteArrayType(T, ASM, Quals);
 }
   } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) {
-T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
+if (getLangOpts().CPlusPlus) {
+  T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals,
+ Brackets);
+} else {
+  // DependentSizedArrayType cannot be handled by C
+  T = Context.getConstantArrayType(T, ConstVal, ArraySize, ASM, Quals);
+}
   } else {
 ExprResult R =
 checkArraySize(*this, ArraySize, ConstVal, VLADiag, VLAIsError);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -369,6 +369,8 @@
   (`#62207 `_)
 - Fix lambdas and other anonymous function names not respecting 
``-fdebug-prefix-map``
   (`#62192 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2579,7 +2579,13 @@
   T = Context.getIncompleteArrayType(T, ASM, Quals);
 }
   } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) {
-T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
+if (getLangOpts().CPlusPlus) {
+  T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals,
+ Brackets);
+} else {
+  // DependentSizedArrayType cannot be handled by C
+  T = Context.getConstantArrayType(T, ConstVal, ArraySize, ASM, Quals);
+}
   } else {
 ExprResult R =
 checkArraySize(*this, ArraySize, ConstVal, VLADiag, VLAIsError);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -369,6 +369,8 @@
   (`#62207 `_)
 - Fix lambdas and other anonymous function names not respecting ``-fdebug-prefix-map``
   (`#62192 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149612: [Sema] avoid merge error type

2023-05-04 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 519675.
HerrCai0907 added a comment.

use nullpt as SizeExpr


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/merge-decls.c


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int 
(*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 
'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 
'char' is not a structure or union}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2579,7 +2579,13 @@
   T = Context.getIncompleteArrayType(T, ASM, Quals);
 }
   } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) {
-T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
+if (getLangOpts().CPlusPlus) {
+  T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals,
+ Brackets);
+} else {
+  // DependentSizedArrayType cannot be handled by C
+  T = Context.getConstantArrayType(T, ConstVal, nullptr, ASM, Quals);
+}
   } else {
 ExprResult R =
 checkArraySize(*this, ArraySize, ConstVal, VLADiag, VLAIsError);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -369,6 +369,8 @@
   (`#62207 `_)
 - Fix lambdas and other anonymous function names not respecting 
``-fdebug-prefix-map``
   (`#62192 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2579,7 +2579,13 @@
   T = Context.getIncompleteArrayType(T, ASM, Quals);
 }
   } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) {
-T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
+if (getLangOpts().CPlusPlus) {
+  T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals,
+ Brackets);
+} else {
+  // DependentSizedArrayType cannot be handled by C
+  T = Context.getConstantArrayType(T, ConstVal, nullptr, ASM, Quals);
+}
   } else {
 ExprResult R =
 checkArraySize(*this, ArraySize, ConstVal, VLADiag, VLAIsError);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -369,6 +369,8 @@
   (`#62207 `_)
 - Fix lambdas and other anonymous function names not respecting ``-fdebug-prefix-map``
   (`#62192 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149612: [Sema] avoid merge error type

2023-05-04 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2582
   } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) {
-T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
+if (getLangOpts().CPlusPlus) {
+  T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals,

erichkeane wrote:
> So I'm still not sure this is the 'right' away about it.  I think we should 
> instead properly handle the `containsErrors` case and just always create a 
> non-dependent sized array, except with the `RecoveryExpr` having the correct 
> type.
For CPP, dependent sized array is acceptable and necessary.

For C, I don't think SemaType is a correctly way to resolve TypoExpr, It should 
be done by `ActOnXXX`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

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


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-05 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 519847.
HerrCai0907 added a comment.

return Diag


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
 WebVector(const WebVector& other) { } // expected-error{{undeclared identifier 'T'}} \
 precxx17-error{{a type specifier is required}} \
-cxx17-error{{deduction guide declaration without trailing return type}} \
-cxx17-error{{deduction guide cannot have a function definition}}
+cxx17-error{{deduction guide declaration without trailing return type}}
 
   template 
   WebVector& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on error.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.getName().getBeginLoc(),
+if (

[PATCH] D149612: [Sema] avoid merge error type

2023-05-05 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 519972.
HerrCai0907 added a comment.

update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-types-errors-json.cpp
  clang/test/AST/ast-dump-types-errors.cpp
  clang/test/Sema/merge-decls.c

Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/test/AST/ast-dump-types-errors.cpp
===
--- clang/test/AST/ast-dump-types-errors.cpp
+++ clang/test/AST/ast-dump-types-errors.cpp
@@ -2,5 +2,5 @@
 
 void test() {
   using ContainsErrors = int[sizeof(undef())];
-  // CHECK: DependentSizedArrayType {{.*}} contains-errors dependent
+  // CHECK: ConstantArrayType {{.*}} 'int[0]' contains-errors dependent 0
 }
Index: clang/test/AST/ast-dump-types-errors-json.cpp
===
--- clang/test/AST/ast-dump-types-errors-json.cpp
+++ clang/test/AST/ast-dump-types-errors-json.cpp
@@ -24,18 +24,19 @@
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "name": "TestContainsErrors",
 // CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT:   "qualType": "int[0]"
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "inner": [
 // CHECK-NEXT:   {
 // CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "DependentSizedArrayType",
+// CHECK-NEXT:"kind": "ConstantArrayType",
 // CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT: "qualType": "int[0]"
 // CHECK-NEXT:},
 // CHECK-NEXT:"containsErrors": true,
 // CHECK-NEXT:"isDependent": true,
 // CHECK-NEXT:"isInstantiationDependent": true,
+// CHECK-NEXT:"size": 0,
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
@@ -43,96 +44,6 @@
 // CHECK-NEXT:  "type": {
 // CHECK-NEXT:   "qualType": "int"
 // CHECK-NEXT:  }
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "UnaryExprOrTypeTraitExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 32,
-// CHECK-NEXT:"tokLen": 6
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 46,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "unsigned long"
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "valueCategory": "prvalue",
-// CHECK-NEXT:  "name": "sizeof",
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParenExpr",
-// CHECK-NEXT:"range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 38,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 46,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: }
-// CHECK-NEXT:},
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": ""
-// CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "lvalue",
-// CHECK-NEXT:"inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "RecoveryExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 39,
-// CHECK-NEXT:"tokLen": 5
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 45,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": ""
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "valueCategory": "lvalue",
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "UnresolvedLookupExpr",
-// CHECK-NEXT:"range": {
-// CHECK-NEXT:

[PATCH] D149612: [Sema] avoid merge error type

2023-05-05 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

> So I'm still not sure this is the 'right' away about it. I think we should 
> instead properly handle the containsErrors case and just always create a 
> non-dependent sized array, except with the RecoveryExpr having the correct 
> type.

You are right. Fix as your suggestion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

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


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2583
+if (ArraySize->containsErrors()) {
+  RecoveryExpr *RE = RecoveryExpr::Create(
+  Context, ArraySize->getType(), ArraySize->getBeginLoc(),

erichkeane wrote:
> Actually thinking further... rather than create a NEW RecoveryExpr, is there 
> a problem KEEPING the ArraySize expression?  It'd likely give more 
> information/keep more AST consistency.
> 
> ALSO, creating this as size-0 has some implications we probably don't want.  
> I wonder if a different for the placeholder would be better?  
> 
> I'D ALSO suggest hoisting this ArraySize->containsError out of the else-if 
> and into its own branch (rather than inside the dependent checks).
> KEEPING the ArraySize expression
Agree.

> creating this as size-0 has some implications we probably don't want.
Do you think we can modify it as 1? But I don't find a better way to identifier 
it as undef or other.

> hoisting this ArraySize->containsError out of the else-if 
Done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 520496.
HerrCai0907 marked 2 inline comments as done.
HerrCai0907 added a comment.

use 1 replace 0 as length


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-types-errors-json.cpp
  clang/test/AST/ast-dump-types-errors.cpp
  clang/test/Sema/merge-decls.c

Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/test/AST/ast-dump-types-errors.cpp
===
--- clang/test/AST/ast-dump-types-errors.cpp
+++ clang/test/AST/ast-dump-types-errors.cpp
@@ -2,5 +2,5 @@
 
 void test() {
   using ContainsErrors = int[sizeof(undef())];
-  // CHECK: DependentSizedArrayType {{.*}} contains-errors dependent
+  // CHECK: ConstantArrayType {{.*}} 'int[1]' contains-errors dependent 1
 }
Index: clang/test/AST/ast-dump-types-errors-json.cpp
===
--- clang/test/AST/ast-dump-types-errors-json.cpp
+++ clang/test/AST/ast-dump-types-errors-json.cpp
@@ -24,18 +24,19 @@
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "name": "TestContainsErrors",
 // CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT:   "qualType": "int[1]"
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "inner": [
 // CHECK-NEXT:   {
 // CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "DependentSizedArrayType",
+// CHECK-NEXT:"kind": "ConstantArrayType",
 // CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT: "qualType": "int[1]"
 // CHECK-NEXT:},
 // CHECK-NEXT:"containsErrors": true,
 // CHECK-NEXT:"isDependent": true,
 // CHECK-NEXT:"isInstantiationDependent": true,
+// CHECK-NEXT:"size": 1,
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
@@ -43,96 +44,6 @@
 // CHECK-NEXT:  "type": {
 // CHECK-NEXT:   "qualType": "int"
 // CHECK-NEXT:  }
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "UnaryExprOrTypeTraitExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 32,
-// CHECK-NEXT:"tokLen": 6
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 46,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "unsigned long"
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "valueCategory": "prvalue",
-// CHECK-NEXT:  "name": "sizeof",
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParenExpr",
-// CHECK-NEXT:"range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 38,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 46,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: }
-// CHECK-NEXT:},
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": ""
-// CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "lvalue",
-// CHECK-NEXT:"inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "RecoveryExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 39,
-// CHECK-NEXT:"tokLen": 5
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 45,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": ""
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "valueCategory": "lvalue",
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "UnresolvedLookupExp

[PATCH] D149612: [Sema] avoid merge error type

2023-05-09 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 520807.
HerrCai0907 added a comment.

add more test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-types-errors-json.cpp
  clang/test/AST/ast-dump-types-errors.cpp
  clang/test/Sema/merge-decls.c

Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,10 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x1[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x1[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
+
+char x2[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}} expected-note {{previous definition is here}}
+char x2[10]; // expected-error {{redefinition of 'x2' with a different type: 'char[10]' vs 'char[1]'}}
Index: clang/test/AST/ast-dump-types-errors.cpp
===
--- clang/test/AST/ast-dump-types-errors.cpp
+++ clang/test/AST/ast-dump-types-errors.cpp
@@ -2,5 +2,5 @@
 
 void test() {
   using ContainsErrors = int[sizeof(undef())];
-  // CHECK: DependentSizedArrayType {{.*}} contains-errors dependent
+  // CHECK: ConstantArrayType {{.*}} 'int[1]' contains-errors dependent 1
 }
Index: clang/test/AST/ast-dump-types-errors-json.cpp
===
--- clang/test/AST/ast-dump-types-errors-json.cpp
+++ clang/test/AST/ast-dump-types-errors-json.cpp
@@ -24,18 +24,19 @@
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "name": "TestContainsErrors",
 // CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT:   "qualType": "int[1]"
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "inner": [
 // CHECK-NEXT:   {
 // CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "DependentSizedArrayType",
+// CHECK-NEXT:"kind": "ConstantArrayType",
 // CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT: "qualType": "int[1]"
 // CHECK-NEXT:},
 // CHECK-NEXT:"containsErrors": true,
 // CHECK-NEXT:"isDependent": true,
 // CHECK-NEXT:"isInstantiationDependent": true,
+// CHECK-NEXT:"size": 1,
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
@@ -43,96 +44,6 @@
 // CHECK-NEXT:  "type": {
 // CHECK-NEXT:   "qualType": "int"
 // CHECK-NEXT:  }
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "UnaryExprOrTypeTraitExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 32,
-// CHECK-NEXT:"tokLen": 6
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 46,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "unsigned long"
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "valueCategory": "prvalue",
-// CHECK-NEXT:  "name": "sizeof",
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParenExpr",
-// CHECK-NEXT:"range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 38,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 46,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: }
-// CHECK-NEXT:},
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": ""
-// CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "lvalue",
-// CHECK-NEXT:"inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "RecoveryExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 39,
-// CHECK-NEXT:"tokLen": 5
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 45,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": ""
-// CHECK-NEXT:  },

[PATCH] D149612: [Sema] avoid merge error type

2023-05-09 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 520808.
HerrCai0907 added a comment.

add more test cases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-types-errors-json.cpp
  clang/test/AST/ast-dump-types-errors.cpp
  clang/test/Sema/merge-decls.c

Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,11 @@
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x1[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x1[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x2[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}} expected-note {{previous definition is here}}
+char x2[10]; // expected-error {{redefinition of 'x2' with a different type: 'char[10]' vs 'char[1]'}}
+char x3[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x3[1];
\ No newline at end of file
Index: clang/test/AST/ast-dump-types-errors.cpp
===
--- clang/test/AST/ast-dump-types-errors.cpp
+++ clang/test/AST/ast-dump-types-errors.cpp
@@ -2,5 +2,5 @@
 
 void test() {
   using ContainsErrors = int[sizeof(undef())];
-  // CHECK: DependentSizedArrayType {{.*}} contains-errors dependent
+  // CHECK: ConstantArrayType {{.*}} 'int[1]' contains-errors dependent 1
 }
Index: clang/test/AST/ast-dump-types-errors-json.cpp
===
--- clang/test/AST/ast-dump-types-errors-json.cpp
+++ clang/test/AST/ast-dump-types-errors-json.cpp
@@ -24,18 +24,19 @@
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "name": "TestContainsErrors",
 // CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT:   "qualType": "int[1]"
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "inner": [
 // CHECK-NEXT:   {
 // CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "DependentSizedArrayType",
+// CHECK-NEXT:"kind": "ConstantArrayType",
 // CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "int[sizeof ((undef))]"
+// CHECK-NEXT: "qualType": "int[1]"
 // CHECK-NEXT:},
 // CHECK-NEXT:"containsErrors": true,
 // CHECK-NEXT:"isDependent": true,
 // CHECK-NEXT:"isInstantiationDependent": true,
+// CHECK-NEXT:"size": 1,
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
@@ -43,96 +44,6 @@
 // CHECK-NEXT:  "type": {
 // CHECK-NEXT:   "qualType": "int"
 // CHECK-NEXT:  }
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "UnaryExprOrTypeTraitExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 32,
-// CHECK-NEXT:"tokLen": 6
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 46,
-// CHECK-NEXT:"tokLen": 1
-// CHECK-NEXT:   }
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "unsigned long"
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "valueCategory": "prvalue",
-// CHECK-NEXT:  "name": "sizeof",
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParenExpr",
-// CHECK-NEXT:"range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 38,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 46,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: }
-// CHECK-NEXT:},
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": ""
-// CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "lvalue",
-// CHECK-NEXT:"inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "RecoveryExpr",
-// CHECK-NEXT:  "range": {
-// CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 39,
-// CHECK-NEXT:"tokLen": 5
-// CHECK-NEXT:   },
-// CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
-// CHECK-NEXT:"col": 45,
-// CHECK-NEXT:"tokLen": 1
-// 

[PATCH] D149612: [Sema] avoid merge error type

2023-05-09 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2583
+if (ArraySize->containsErrors()) {
+  RecoveryExpr *RE = RecoveryExpr::Create(
+  Context, ArraySize->getType(), ArraySize->getBeginLoc(),

erichkeane wrote:
> HerrCai0907 wrote:
> > erichkeane wrote:
> > > Actually thinking further... rather than create a NEW RecoveryExpr, is 
> > > there a problem KEEPING the ArraySize expression?  It'd likely give more 
> > > information/keep more AST consistency.
> > > 
> > > ALSO, creating this as size-0 has some implications we probably don't 
> > > want.  I wonder if a different for the placeholder would be better?  
> > > 
> > > I'D ALSO suggest hoisting this ArraySize->containsError out of the 
> > > else-if and into its own branch (rather than inside the dependent checks).
> > > KEEPING the ArraySize expression
> > Agree.
> > 
> > > creating this as size-0 has some implications we probably don't want.
> > Do you think we can modify it as 1? But I don't find a better way to 
> > identifier it as undef or other.
> > 
> > > hoisting this ArraySize->containsError out of the else-if 
> > Done
> I don't have good evidence for what else we could do (whether an incomplete 
> or variable type would be better), but at least 1 is 'legal', so perhaps we 
> can live with this for now and see if there is any fallout.
> 
> What happens if we try to 'merge' a valid and an invalid here? Does it make 
> the experience worse?  So same example you added below, but the 1st one has 
> no error in its brackets?
I add test case for this scenario. I think it will not confuse developer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149612/new/

https://reviews.llvm.org/D149612

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


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-15 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

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


  1   2   >