[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,35 @@
+const char8_t x = 1;
+
+template requires true
+const int y = requires { typename T::type; requires T::value; };
+
+int f(){ co_await 1; }
+
+// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:3 %s | FileCheck 
--check-prefix=CHECK-TOP-LEVEL %s
+// CHECK-TOP-LEVEL: const
+// CHECK-TOP-LEVEL: consteval
+// CHECK-TOP-LEVEL: constexpr
+// CHECK-TOP-LEVEL: constinit
+
+// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:12 %s | FileCheck 
--check-prefix=CHECK-TOP-LEVEL %s
+// CHECK-TOP-LEVEL: char8_t
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:3 %s | FileCheck 
--check-prefix=CHECK-REQUIRES %s
+// CHECK-REQUIRES: concept
+// CHECK-REQUIRES: const
+// CHECK-REQUIRES: consteval
+// CHECK-REQUIRES: constexpr
+// CHECK-REQUIRES: constinit
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:3:27 %s | FileCheck 
--check-prefix=CHECK-REQUIRES %s
+// CHECK-REQUIRES: requires
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:20 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// CHECK-CC1-NEXT: COMPLETION: Pattern: [#bool#]requires (<#parameters#>) {
+// CHECK-CC1-NEXT: <#requirements#>
+// CHECK-CC1-NEXT: }
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:6:13 %s | FileCheck 
--check-prefix=CHECK-COAWAIT %s
+// CHECK-COAWAIT: Pattern : co_await <#expression#>
+// CHECK-COAWAIT: Pattern : co_return <#expression#>;
+// CHECK-COAWAIT: Pattern : co_yield <#expression#>

zwuis wrote:

A new line character is required at end of file.

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


[clang] [Clang] Support non-reference structured bindings with braced array as initializer (PR #102581)

2024-08-09 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/102581

When initializing non-reference structured bindings from braced array, array 
copy will be performed, which is a special case not following 
list-initialization.

This PR adds support for this case.

Fixes #31813.

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH] Support non-reference structured bindings with braced array
 as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  

[clang] [Clang] Fix Handling of Init Capture with Parameter Packs in LambdaScopeForCallOperatorInstantiationRAII (PR #100766)

2024-08-09 Thread Yanzuo Liu via cfe-commits


@@ -712,22 +712,30 @@ bool Sema::addInstantiatedCapturesToScope(
   auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
   unsigned Index) {
 ValueDecl *CapturedVar = LambdaClass->getCapture(Index)->getCapturedVar();
-if (CapturedVar->isInitCapture())
-  Scope.InstantiatedLocal(CapturedPattern, CapturedVar);
+assert(CapturedVar->isInitCapture());
+Scope.InstantiatedLocal(CapturedPattern, CapturedVar);
   };
 
   for (const LambdaCapture &CapturePattern : LambdaPattern->captures()) {
 if (!CapturePattern.capturesVariable()) {
   Instantiated++;
   continue;
 }
-const ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();
+ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();
+
+if (!CapturedPattern->isInitCapture()) {
+  continue;
+}
+
 if (!CapturedPattern->isParameterPack()) {
   AddSingleCapture(CapturedPattern, Instantiated++);
 } else {
   Scope.MakeInstantiatedLocalArgPack(CapturedPattern);
-  std::optional NumArgumentsInExpansion =
-  getNumArgumentsInExpansion(CapturedPattern->getType(), TemplateArgs);
+  SmallVector Unexpanded;
+  SemaRef.collectUnexpandedParameterPacks(
+  dyn_cast(CapturedPattern)->getInit(), Unexpanded);

zwuis wrote:

Why not use `cast`?

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


[clang] [Clang][AST] Add Test Cases for Reference Qualifiers in Opr Overload (PR #102878)

2024-08-12 Thread Yanzuo Liu via cfe-commits


@@ -54,4 +54,18 @@ struct B {
   void operator delete(void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
   void operator delete[](void*) volatile; //expected-error {{static member 
function cannot have 'volatile' qualifier}}
 };
+
+struct C {

zwuis wrote:

```suggestion
struct GH102422 {
```

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


[clang] [llvm] add comment (PR #103046)

2024-08-13 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][AST] Add Test Cases for Reference Qualifiers in Opr Overload (PR #102878)

2024-08-15 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

CC @shafik

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectField::IdentifierNamespace` (PR #100525)

2024-07-25 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/100525

There is a `IDNS_Ordinary` flag in `IndirectField::IdentifierNamespace` so that 
members in nested anonymous struct/union can be found as ordinary identifiers.

```c
struct S {
  struct { int x; };
  // Previous behaviour: `x` in previous line is found
  // Expected: nothing is found
  int arr[sizeof(x)];
};
```

This PR fixes this issue.

Fixes #31295.

>From 217d3978f48ea074420fecd432b0b65b7e1c5b58 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Thu, 25 Jul 2024 14:50:21 +0800
Subject: [PATCH] Remove `IDNS_Ordinary` flag in
 `IndirectField::IdentifierNamespace`

---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/DeclBase.cpp  | 3 +--
 clang/test/Parser/namelookup-anonymous-struct.c | 6 ++
 3 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/namelookup-anonymous-struct.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 83fd5dc31547e..24be9e26a9adf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -137,6 +137,9 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Fixed a crash in C due to incorrect lookup that members in nested anonymous 
struct/union
+  can be found as ordinary identifiers in struct/union definition. (#GH31295)
+
 OpenACC Specific Changes
 
 
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index bc5a9206c0db2..a1f70546bde42 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -879,8 +879,6 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) 
{
   return IDNS_Ordinary;
 case Label:
   return IDNS_Label;
-case IndirectField:
-  return IDNS_Ordinary | IDNS_Member;
 
 case Binding:
 case NonTypeTemplateParm:
@@ -918,6 +916,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) 
{
   return IDNS_ObjCProtocol;
 
 case Field:
+case IndirectField:
 case ObjCAtDefsField:
 case ObjCIvar:
   return IDNS_Member;
diff --git a/clang/test/Parser/namelookup-anonymous-struct.c 
b/clang/test/Parser/namelookup-anonymous-struct.c
new file mode 100644
index 0..cb691c22f97ff
--- /dev/null
+++ b/clang/test/Parser/namelookup-anonymous-struct.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c11 -verify %s
+
+struct GH31295 {
+  struct { int x; };
+  int arr[sizeof(x)]; // expected-error{{use of undeclared identifier 'x'}}
+};

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-25 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-25 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-26 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Thank you for your review!

I don't have commit access. Please help me merge this PR if it's ready.

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-26 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

> I don’t believe the standard supports anonymous structs in C++

Do we need tests about anonymous union? C++ standard supports it.

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


[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-27 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/102581

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH 1/5] Support non-reference structured bindings with braced
 array as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  //
+  // This is a special case not following list-initialization.
+  if (isa(DestAT) &&
+  Entity.getKind() == InitializedEntity::EK_Variable &&
+  isa(Entity.getDecl())) {
+

[clang] [Clang] Support initializing structured bindings from an array with direct-list-initialization (PR #102581)

2024-08-27 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Support initializing structured bindings from an array with direct-list-initialization (PR #102581)

2024-08-27 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Support initializing structured bindings from an array with direct-list-initialization (PR #102581)

2024-08-27 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/102581

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH 1/5] Support non-reference structured bindings with braced
 array as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  //
+  // This is a special case not following list-initialization.
+  if (isa(DestAT) &&
+  Entity.getKind() == InitializedEntity::EK_Variable &&
+  isa(Entity.getDecl())) {
+

[clang] [Clang] Support initializing structured bindings from an array with direct-list-initialization (PR #102581)

2024-08-27 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Suggestions are applied. Thank you for your review!

I don't have commit accees. Please help me merge this PR if it's ready.

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


[clang] [clang-tools-extra] [lldb] [llvm] [mlir] [Support] Validate number of arguments passed to formatv() (PR #105745)

2024-08-22 Thread Yanzuo Liu via cfe-commits


@@ -74,16 +75,31 @@ class formatv_object_base {
   static std::pair
   splitLiteralAndReplacement(StringRef Fmt);
 
-  formatv_object_base(StringRef Fmt,
+  formatv_object_base(StringRef Fmt, bool ValidateNumArgs,
   ArrayRef Adapters)
-  : Fmt(Fmt), Adapters(Adapters) {}
+  : Fmt(Fmt), ValidateNumArgs(ValidateNumArgs), Adapters(Adapters) {}
 
   formatv_object_base(formatv_object_base const &rhs) = delete;
   formatv_object_base(formatv_object_base &&rhs) = default;
 
 public:
   void format(raw_ostream &S) const {
-for (auto &R : parseFormatString(Fmt)) {
+const auto [Replacements, NumExpectedParams] = parseFormatString(Fmt);
+// Fail formatv() call if the number of replacement parameters provided
+// does not match the expected number after parsing the format string.
+// Assert in debug builds.
+if (ValidateNumArgs && NumExpectedParams != Adapters.size()) {
+  errs() << "Invalid format() in formatv: " << Fmt << "\n";
+  assert(0 &&
+ "Mismatch between replacement parameters expected and provided");
+
+  S << "formatv() error: " << NumExpectedParams
+<< " replacement parameters expected, but " << Adapters.size()
+<< " provided";

zwuis wrote:

Do we need to add a `\n` here?

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


[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-23 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-23 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-23 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-23 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/102581

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH 1/2] Support non-reference structured bindings with braced
 array as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  //
+  // This is a special case not following list-initialization.
+  if (isa(DestAT) &&
+  Entity.getKind() == InitializedEntity::EK_Variable &&
+  isa(Entity.getDecl())) {
+

[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-23 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/102581

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH 1/2] Support non-reference structured bindings with braced
 array as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  //
+  // This is a special case not following list-initialization.
+  if (isa(DestAT) &&
+  Entity.getKind() == InitializedEntity::EK_Variable &&
+  isa(Entity.getDecl())) {
+

[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

2024-08-23 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/102581

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH 1/3] Support non-reference structured bindings with braced
 array as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  //
+  // This is a special case not following list-initialization.
+  if (isa(DestAT) &&
+  Entity.getKind() == InitializedEntity::EK_Variable &&
+  isa(Entity.getDecl())) {
+

[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

2024-08-25 Thread Yanzuo Liu via cfe-commits


@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager 
&SourceMgr,
   return false;
 }
 
+static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) {
+  const LangOptions &Lang = PP.getLangOpts();
+  const StringRef Name = II->getName();
+
+  if (Lang.CPlusPlus26)
+return Name == "indeterminate";
+  if (Lang.CPlusPlus23)
+return Name == "assume";

zwuis wrote:

It seems that `#define assume` will not trigger diagnostic in C++26. Do I 
misunderstand this code?

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


[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

2024-08-25 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

2024-08-26 Thread Yanzuo Liu via cfe-commits


@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager 
&SourceMgr,
   return false;
 }
 
+static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) {
+  const LangOptions &Lang = PP.getLangOpts();
+  const StringRef Name = II->getName();
+
+  if (Lang.CPlusPlus26)
+return Name == "indeterminate";
+  if (Lang.CPlusPlus23)
+return Name == "assume";

zwuis wrote:

> It seems that `#define assume` will not trigger diagnostic in C++26.

I mean, control flow will reach line 185 and check if the name is 
`"indeterminate"` only, not check `"assume"`.

I think it shoule be
```cpp
if (Lang.CPlusPlus26 && Name == "indeterminate")
  return true;
```

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


[clang] [Clang] Do not perform integral promotion if operands of expression `x ? : y` have the same type (PR #108837)

2024-09-16 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/108837

According to [[expr.cond]/5](https://eel.is/c++draft/expr.cond#5) and 
[[expr.cond]/7.1](https://eel.is/c++draft/expr.cond#7.1), no conversion should 
be performed to compute result type if middle operand and right operand have 
the same type regardless of their value catagories.

Fixes #15998.

>From 7e5f88c322852939ae68c65f6adf4a5d2973d095 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 21:50:11 +0800
Subject: [PATCH] Fix computing result type of conditional operand

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  4 +---
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 19 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/conditional-gnu-ext.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17ec1fe0b946de..db8a7568a12114 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,6 +389,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fixed a bug in computing result type of conditional operator with omitted 
middle operand
+  (a GNU extension). (#GH15998)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..8414a55e4868b9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8785,11 +8785,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
   commonExpr = result.get();
 }
 // We usually want to apply unary conversions *before* saving, except
-// in the special case of a C++ l-value conditional.
+// in the special case in C++ that operands have the same type.
 if (!(getLangOpts().CPlusPlus
   && !commonExpr->isTypeDependent()
-  && commonExpr->getValueKind() == RHSExpr->getValueKind()
-  && commonExpr->isGLValue()
   && commonExpr->isOrdinaryOrBitFieldObject()
   && RHSExpr->isOrdinaryOrBitFieldObject()
   && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
diff --git a/clang/test/SemaCXX/conditional-gnu-ext.cpp 
b/clang/test/SemaCXX/conditional-gnu-ext.cpp
new file mode 100644
index 00..83a6fff8467863
--- /dev/null
+++ b/clang/test/SemaCXX/conditional-gnu-ext.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter
+// expected-no-diagnostics
+
+/*
+FIXME: Support constexpr
+
+constexpr int evaluate_once(int x) {
+  return (++x) ? : 10;
+}
+static_assert(evaluate_once(0) == 1, "");
+*/
+
+namespace GH15998 {
+  enum E { Zero, One };
+  E test(E e) {
+return e ? : One;
+  }
+}

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


[clang] [Clang] Do not perform integral promotion if operands of expression `x ? : y` have the same type (PR #108837)

2024-09-16 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang] Do not perform integral promotion if operands of expression `x ? : y` have the same type (PR #108837)

2024-09-16 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/108837

>From 7e5f88c322852939ae68c65f6adf4a5d2973d095 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 21:50:11 +0800
Subject: [PATCH 1/2] Fix computing result type of conditional operand

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  4 +---
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 19 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/conditional-gnu-ext.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17ec1fe0b946de..db8a7568a12114 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,6 +389,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fixed a bug in computing result type of conditional operator with omitted 
middle operand
+  (a GNU extension). (#GH15998)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..8414a55e4868b9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8785,11 +8785,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
   commonExpr = result.get();
 }
 // We usually want to apply unary conversions *before* saving, except
-// in the special case of a C++ l-value conditional.
+// in the special case in C++ that operands have the same type.
 if (!(getLangOpts().CPlusPlus
   && !commonExpr->isTypeDependent()
-  && commonExpr->getValueKind() == RHSExpr->getValueKind()
-  && commonExpr->isGLValue()
   && commonExpr->isOrdinaryOrBitFieldObject()
   && RHSExpr->isOrdinaryOrBitFieldObject()
   && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
diff --git a/clang/test/SemaCXX/conditional-gnu-ext.cpp 
b/clang/test/SemaCXX/conditional-gnu-ext.cpp
new file mode 100644
index 00..83a6fff8467863
--- /dev/null
+++ b/clang/test/SemaCXX/conditional-gnu-ext.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter
+// expected-no-diagnostics
+
+/*
+FIXME: Support constexpr
+
+constexpr int evaluate_once(int x) {
+  return (++x) ? : 10;
+}
+static_assert(evaluate_once(0) == 1, "");
+*/
+
+namespace GH15998 {
+  enum E { Zero, One };
+  E test(E e) {
+return e ? : One;
+  }
+}

>From 447c8b9c6e957308c9ff62e8c83b15b12f7fc1cb Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 23:05:50 +0800
Subject: [PATCH 2/2] Format code

---
 clang/lib/Sema/SemaExpr.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8414a55e4868b9..c232d40ca31ac6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8786,11 +8786,10 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
 }
 // We usually want to apply unary conversions *before* saving, except
 // in the special case in C++ that operands have the same type.
-if (!(getLangOpts().CPlusPlus
-  && !commonExpr->isTypeDependent()
-  && commonExpr->isOrdinaryOrBitFieldObject()
-  && RHSExpr->isOrdinaryOrBitFieldObject()
-  && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
+if (!(getLangOpts().CPlusPlus && !commonExpr->isTypeDependent() &&
+  commonExpr->isOrdinaryOrBitFieldObject() &&
+  RHSExpr->isOrdinaryOrBitFieldObject() &&
+  Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
   ExprResult commonRes = UsualUnaryConversions(commonExpr);
   if (commonRes.isInvalid())
 return ExprError();

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


[clang] [llvm] [llvm] Deprecate Type::getPointerTo() (PR #113331)

2024-10-22 Thread Yanzuo Liu via cfe-commits


@@ -471,8 +471,9 @@ class Type {
   static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
-  /// PointerType::get(Foo, AddrSpace).
+  /// PointerType::get(Ctx, AddrSpace).
   /// TODO: Remove this after opaque pointer transition is complete.
+  [[deprecated("Use PointerType::get instead")]]

zwuis wrote:

Can we use `LLVM_DEPRECATED` in llvm/Support/Compiler.h?

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


[clang] [Clang] update reasoned delete diagnostic kind to use Extension, making it pedantic only (PR #114713)

2024-11-03 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

I think we should make these changes to all backported features.

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


[clang] [llvm] [clang] Add/enhance documentation for some important classes. (PR #109795)

2024-09-24 Thread Yanzuo Liu via cfe-commits


@@ -79,8 +79,24 @@ enum class StringLiteralKind;
 // AST classes for statements.
 
//===--===//
 
-/// Stmt - This represents one statement.
+/// A statement or expression in the program.
 ///
+/// This is the base for the hierarchy of statements (ForStmt, ReturnStmt...)
+/// as well as expressions (Expr, CastExpr, IntegerLiteral...).
+/// Classing expressions as Stmt allows them to appear as statements without
+/// needing an extra "expression-statement" node.
+///
+/// Statements can have children and so form trees. e.g. `while (i>0) i--;`
+///
+///   WhileStmt
+///   |-BinaryOperator >
+///   | |-DeclRefExpr i
+///   | `-IntegerLiteral 0
+///   `-UnaryOperator --
+///   DeclRefExpr i
+///

zwuis wrote:

We can use `\code` and `\endcode` commands for code block so that it is treated 
as code instead of text by doxygen.

```cpp
/// \code
///   WhileStmt
///   |-BinaryOperator >
///   ...
/// \endcode
```

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Yanzuo Liu via cfe-commits

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


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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Yanzuo Liu via cfe-commits


@@ -3599,7 +3599,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/591.html";>591
 CD4
 When a dependent base class is the current instantiation
-No
+Yes

zwuis wrote:

```suggestion
Clang 20
```


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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Yanzuo Liu via cfe-commits


@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes

zwuis wrote:

```suggestion
namespace cwg591 { // cwg591: 20
```


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


[clang] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

2024-11-26 Thread Yanzuo Liu via cfe-commits


@@ -1639,6 +1639,13 @@ SourceLocation CallExpr::getBeginLoc() const {
   if (const auto *OCE = dyn_cast(this))
 return OCE->getBeginLoc();
 
+  if (const CXXMethodDecl *Method =
+  dyn_cast_or_null(getCalleeDecl());

zwuis wrote:

```suggestion
  dyn_cast_if_present(getCalleeDecl());
```


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


[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2024-12-04 Thread Yanzuo Liu via cfe-commits


@@ -1619,8 +1619,9 @@ std::pair
 CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
   // If the callee is marked nodiscard, return that attribute
   const Decl *D = getCalleeDecl();
-  if (const auto *A = D->getAttr())
-return {nullptr, A};
+  if (D != nullptr)

zwuis wrote:

```suggestion
  if (const Decl *D = getCalleeDecl())
```


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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread Yanzuo Liu via cfe-commits


@@ -365,3 +365,9 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+// PR119098
+void test20(char x) {
+  double value;
+  asm ("fabs" : "=t" (value): "0" (x)); // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+}

zwuis wrote:

nit: add a new line character at EOF

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread Yanzuo Liu via cfe-commits


@@ -365,3 +365,9 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+// PR119098

zwuis wrote:

```suggestion
// GH118892
```


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


[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

2025-02-03 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/124793

>From 16596add29b63ee0282e026dec7b1d5946863113 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 00:38:15 +0800
Subject: [PATCH 1/3] Fix wrong initialization kind

---
 clang/lib/Sema/SemaInit.cpp|  5 +++--
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 21 ++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf4222056..5552fce55f1310 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4861,8 +4861,9 @@ static void TryListInitialization(Sema &S,
 S.Context.hasSameUnqualifiedType(SubInit[0]->getType(), DestType) 
&&
 "Deduced to other type?");
 TryArrayCopy(S,
- InitializationKind::CreateCopy(Kind.getLocation(),
-InitList->getLBraceLoc()),
+ InitializationKind::CreateDirect(Kind.getLocation(),
+  InitList->getLBraceLoc(),
+  
InitList->getRBraceLoc()),
  Entity, SubInit[0], DestType, Sequence,
  TreatUnavailableAsInvalid);
 if (Sequence)
diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index a8914fe4e9cd82..b3d98e44990f61 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -200,38 +200,37 @@ namespace lambdas {
 
 namespace by_value_array_copy {
   struct explicit_copy {
-explicit_copy() = default; // expected-note 2{{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
-explicit explicit_copy(const explicit_copy&) = default; // expected-note 
2{{explicit constructor is not a candidate}}
+explicit_copy() = default; // expected-note {{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
+explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
   constexpr int direct_initialization_for_elements() {
 explicit_copy ec_arr[2];
 auto [a1, b1](ec_arr);
+auto [a2, b2]{ec_arr};
 
 int arr[3]{1, 2, 3};
-auto [a2, b2, c2](arr);
+auto [a3, b3, c3](arr);
+auto [a4, b4, c4]{arr}; // GH31813
 arr[0]--;
-return a2 + b2 + c2 + arr[0];
+return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
   }
-  static_assert(direct_initialization_for_elements() == 6);
+  static_assert(direct_initialization_for_elements() == 12);
 
   constexpr int copy_initialization_for_elements() {
 int arr[2]{4, 5};
 auto [a1, b1] = arr;
-auto [a2, b2]{arr}; // GH31813
 arr[0] = 0;
-return a1 + b1 + a2 + b2 + arr[0];
+return a1 + b1 + arr[0];
   }
-  static_assert(copy_initialization_for_elements() == 18);
+  static_assert(copy_initialization_for_elements() == 9);
 
   void copy_initialization_for_elements_with_explicit_copy_ctor() {
 explicit_copy ec_arr[2];
 auto [a1, b1] = ec_arr; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
-auto [a2, b2]{ec_arr}; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
 
 // Test prvalue
 using T = explicit_copy[2];
-auto [a3, b3] = T{};
-auto [a4, b4]{T{}};
+auto [a2, b2] = T{};
   }
 } // namespace by_value_array_copy

>From ad033c917db457ebe68b4556a482e9ba56b4746d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 10:28:21 +0800
Subject: [PATCH 2/3] Make tests more clear

---
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 39 ++
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index b3d98e44990f61..95c64bc3b8bff6 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -204,33 +204,28 @@ namespace by_value_array_copy {
 explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
-  constexpr int direct_initialization_for_elements() {
-explicit_copy ec_arr[2];
-auto [a1, b1](ec_arr);
-auto [a2, b2]{ec_arr};
-
-int arr[3]{1, 2, 3};
-auto [a3, b3, c3](arr);
-auto [a4, b4, c4]{arr}; // GH31813
-arr[0]--;
-return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
-  }
-  static_assert(direct_initialization_for_elements() == 12);
+  constexpr int simple_array_elements() {
+int arr[2]{1, 2};
+
+auto [a1, a2] = arr;
+auto [b1, b2](arr);
+auto [c1, c2]{arr}; // GH31813
 
-  constexpr int copy_initialization_for_elements() {
-int arr[2]{4, 5};
-auto [a1, b1] = arr;
 arr[0] = 0;
-return a1 + b1 + arr[0];
+  

[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

2025-02-04 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/124793

>From 16596add29b63ee0282e026dec7b1d5946863113 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 00:38:15 +0800
Subject: [PATCH 1/4] Fix wrong initialization kind

---
 clang/lib/Sema/SemaInit.cpp|  5 +++--
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 21 ++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf4222056..5552fce55f1310 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4861,8 +4861,9 @@ static void TryListInitialization(Sema &S,
 S.Context.hasSameUnqualifiedType(SubInit[0]->getType(), DestType) 
&&
 "Deduced to other type?");
 TryArrayCopy(S,
- InitializationKind::CreateCopy(Kind.getLocation(),
-InitList->getLBraceLoc()),
+ InitializationKind::CreateDirect(Kind.getLocation(),
+  InitList->getLBraceLoc(),
+  
InitList->getRBraceLoc()),
  Entity, SubInit[0], DestType, Sequence,
  TreatUnavailableAsInvalid);
 if (Sequence)
diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index a8914fe4e9cd82..b3d98e44990f61 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -200,38 +200,37 @@ namespace lambdas {
 
 namespace by_value_array_copy {
   struct explicit_copy {
-explicit_copy() = default; // expected-note 2{{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
-explicit explicit_copy(const explicit_copy&) = default; // expected-note 
2{{explicit constructor is not a candidate}}
+explicit_copy() = default; // expected-note {{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
+explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
   constexpr int direct_initialization_for_elements() {
 explicit_copy ec_arr[2];
 auto [a1, b1](ec_arr);
+auto [a2, b2]{ec_arr};
 
 int arr[3]{1, 2, 3};
-auto [a2, b2, c2](arr);
+auto [a3, b3, c3](arr);
+auto [a4, b4, c4]{arr}; // GH31813
 arr[0]--;
-return a2 + b2 + c2 + arr[0];
+return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
   }
-  static_assert(direct_initialization_for_elements() == 6);
+  static_assert(direct_initialization_for_elements() == 12);
 
   constexpr int copy_initialization_for_elements() {
 int arr[2]{4, 5};
 auto [a1, b1] = arr;
-auto [a2, b2]{arr}; // GH31813
 arr[0] = 0;
-return a1 + b1 + a2 + b2 + arr[0];
+return a1 + b1 + arr[0];
   }
-  static_assert(copy_initialization_for_elements() == 18);
+  static_assert(copy_initialization_for_elements() == 9);
 
   void copy_initialization_for_elements_with_explicit_copy_ctor() {
 explicit_copy ec_arr[2];
 auto [a1, b1] = ec_arr; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
-auto [a2, b2]{ec_arr}; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
 
 // Test prvalue
 using T = explicit_copy[2];
-auto [a3, b3] = T{};
-auto [a4, b4]{T{}};
+auto [a2, b2] = T{};
   }
 } // namespace by_value_array_copy

>From ad033c917db457ebe68b4556a482e9ba56b4746d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 10:28:21 +0800
Subject: [PATCH 2/4] Make tests more clear

---
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 39 ++
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index b3d98e44990f61..95c64bc3b8bff6 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -204,33 +204,28 @@ namespace by_value_array_copy {
 explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
-  constexpr int direct_initialization_for_elements() {
-explicit_copy ec_arr[2];
-auto [a1, b1](ec_arr);
-auto [a2, b2]{ec_arr};
-
-int arr[3]{1, 2, 3};
-auto [a3, b3, c3](arr);
-auto [a4, b4, c4]{arr}; // GH31813
-arr[0]--;
-return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
-  }
-  static_assert(direct_initialization_for_elements() == 12);
+  constexpr int simple_array_elements() {
+int arr[2]{1, 2};
+
+auto [a1, a2] = arr;
+auto [b1, b2](arr);
+auto [c1, c2]{arr}; // GH31813
 
-  constexpr int copy_initialization_for_elements() {
-int arr[2]{4, 5};
-auto [a1, b1] = arr;
 arr[0] = 0;
-return a1 + b1 + arr[0];
+  

[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

2025-02-04 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/124793

>From 16596add29b63ee0282e026dec7b1d5946863113 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 00:38:15 +0800
Subject: [PATCH 1/4] Fix wrong initialization kind

---
 clang/lib/Sema/SemaInit.cpp|  5 +++--
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 21 ++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf4222056..5552fce55f1310 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4861,8 +4861,9 @@ static void TryListInitialization(Sema &S,
 S.Context.hasSameUnqualifiedType(SubInit[0]->getType(), DestType) 
&&
 "Deduced to other type?");
 TryArrayCopy(S,
- InitializationKind::CreateCopy(Kind.getLocation(),
-InitList->getLBraceLoc()),
+ InitializationKind::CreateDirect(Kind.getLocation(),
+  InitList->getLBraceLoc(),
+  
InitList->getRBraceLoc()),
  Entity, SubInit[0], DestType, Sequence,
  TreatUnavailableAsInvalid);
 if (Sequence)
diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index a8914fe4e9cd82..b3d98e44990f61 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -200,38 +200,37 @@ namespace lambdas {
 
 namespace by_value_array_copy {
   struct explicit_copy {
-explicit_copy() = default; // expected-note 2{{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
-explicit explicit_copy(const explicit_copy&) = default; // expected-note 
2{{explicit constructor is not a candidate}}
+explicit_copy() = default; // expected-note {{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
+explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
   constexpr int direct_initialization_for_elements() {
 explicit_copy ec_arr[2];
 auto [a1, b1](ec_arr);
+auto [a2, b2]{ec_arr};
 
 int arr[3]{1, 2, 3};
-auto [a2, b2, c2](arr);
+auto [a3, b3, c3](arr);
+auto [a4, b4, c4]{arr}; // GH31813
 arr[0]--;
-return a2 + b2 + c2 + arr[0];
+return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
   }
-  static_assert(direct_initialization_for_elements() == 6);
+  static_assert(direct_initialization_for_elements() == 12);
 
   constexpr int copy_initialization_for_elements() {
 int arr[2]{4, 5};
 auto [a1, b1] = arr;
-auto [a2, b2]{arr}; // GH31813
 arr[0] = 0;
-return a1 + b1 + a2 + b2 + arr[0];
+return a1 + b1 + arr[0];
   }
-  static_assert(copy_initialization_for_elements() == 18);
+  static_assert(copy_initialization_for_elements() == 9);
 
   void copy_initialization_for_elements_with_explicit_copy_ctor() {
 explicit_copy ec_arr[2];
 auto [a1, b1] = ec_arr; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
-auto [a2, b2]{ec_arr}; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
 
 // Test prvalue
 using T = explicit_copy[2];
-auto [a3, b3] = T{};
-auto [a4, b4]{T{}};
+auto [a2, b2] = T{};
   }
 } // namespace by_value_array_copy

>From ad033c917db457ebe68b4556a482e9ba56b4746d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 10:28:21 +0800
Subject: [PATCH 2/4] Make tests more clear

---
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 39 ++
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index b3d98e44990f61..95c64bc3b8bff6 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -204,33 +204,28 @@ namespace by_value_array_copy {
 explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
-  constexpr int direct_initialization_for_elements() {
-explicit_copy ec_arr[2];
-auto [a1, b1](ec_arr);
-auto [a2, b2]{ec_arr};
-
-int arr[3]{1, 2, 3};
-auto [a3, b3, c3](arr);
-auto [a4, b4, c4]{arr}; // GH31813
-arr[0]--;
-return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
-  }
-  static_assert(direct_initialization_for_elements() == 12);
+  constexpr int simple_array_elements() {
+int arr[2]{1, 2};
+
+auto [a1, a2] = arr;
+auto [b1, b2](arr);
+auto [c1, c2]{arr}; // GH31813
 
-  constexpr int copy_initialization_for_elements() {
-int arr[2]{4, 5};
-auto [a1, b1] = arr;
 arr[0] = 0;
-return a1 + b1 + arr[0];
+  

[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

2025-02-07 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/124793

>From 16596add29b63ee0282e026dec7b1d5946863113 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 00:38:15 +0800
Subject: [PATCH 1/4] Fix wrong initialization kind

---
 clang/lib/Sema/SemaInit.cpp|  5 +++--
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 21 ++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf42220568..5552fce55f13106 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4861,8 +4861,9 @@ static void TryListInitialization(Sema &S,
 S.Context.hasSameUnqualifiedType(SubInit[0]->getType(), DestType) 
&&
 "Deduced to other type?");
 TryArrayCopy(S,
- InitializationKind::CreateCopy(Kind.getLocation(),
-InitList->getLBraceLoc()),
+ InitializationKind::CreateDirect(Kind.getLocation(),
+  InitList->getLBraceLoc(),
+  
InitList->getRBraceLoc()),
  Entity, SubInit[0], DestType, Sequence,
  TreatUnavailableAsInvalid);
 if (Sequence)
diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index a8914fe4e9cd823..b3d98e44990f610 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -200,38 +200,37 @@ namespace lambdas {
 
 namespace by_value_array_copy {
   struct explicit_copy {
-explicit_copy() = default; // expected-note 2{{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
-explicit explicit_copy(const explicit_copy&) = default; // expected-note 
2{{explicit constructor is not a candidate}}
+explicit_copy() = default; // expected-note {{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
+explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
   constexpr int direct_initialization_for_elements() {
 explicit_copy ec_arr[2];
 auto [a1, b1](ec_arr);
+auto [a2, b2]{ec_arr};
 
 int arr[3]{1, 2, 3};
-auto [a2, b2, c2](arr);
+auto [a3, b3, c3](arr);
+auto [a4, b4, c4]{arr}; // GH31813
 arr[0]--;
-return a2 + b2 + c2 + arr[0];
+return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
   }
-  static_assert(direct_initialization_for_elements() == 6);
+  static_assert(direct_initialization_for_elements() == 12);
 
   constexpr int copy_initialization_for_elements() {
 int arr[2]{4, 5};
 auto [a1, b1] = arr;
-auto [a2, b2]{arr}; // GH31813
 arr[0] = 0;
-return a1 + b1 + a2 + b2 + arr[0];
+return a1 + b1 + arr[0];
   }
-  static_assert(copy_initialization_for_elements() == 18);
+  static_assert(copy_initialization_for_elements() == 9);
 
   void copy_initialization_for_elements_with_explicit_copy_ctor() {
 explicit_copy ec_arr[2];
 auto [a1, b1] = ec_arr; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
-auto [a2, b2]{ec_arr}; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
 
 // Test prvalue
 using T = explicit_copy[2];
-auto [a3, b3] = T{};
-auto [a4, b4]{T{}};
+auto [a2, b2] = T{};
   }
 } // namespace by_value_array_copy

>From ad033c917db457ebe68b4556a482e9ba56b4746d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 10:28:21 +0800
Subject: [PATCH 2/4] Make tests more clear

---
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 39 ++
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index b3d98e44990f610..95c64bc3b8bff61 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -204,33 +204,28 @@ namespace by_value_array_copy {
 explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
-  constexpr int direct_initialization_for_elements() {
-explicit_copy ec_arr[2];
-auto [a1, b1](ec_arr);
-auto [a2, b2]{ec_arr};
-
-int arr[3]{1, 2, 3};
-auto [a3, b3, c3](arr);
-auto [a4, b4, c4]{arr}; // GH31813
-arr[0]--;
-return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
-  }
-  static_assert(direct_initialization_for_elements() == 12);
+  constexpr int simple_array_elements() {
+int arr[2]{1, 2};
+
+auto [a1, a2] = arr;
+auto [b1, b2](arr);
+auto [c1, c2]{arr}; // GH31813
 
-  constexpr int copy_initialization_for_elements() {
-int arr[2]{4, 5};
-auto [a1, b1] = arr;
 arr[0] = 0;
-return a1 + b1 + arr[0

[clang] [Clang][NFC] Add test for CWG2285 "Issues with structured bindings" (PR #126421)

2025-02-10 Thread Yanzuo Liu via cfe-commits


@@ -196,6 +196,16 @@ void g() {
 #endif
 } // namespace cwg2277
 
+namespace cwg2285 { // cwg2285: 4

zwuis wrote:

> It seems that Clang 5 was the first release which exhibits the correct 
> behavior: https://godbolt.org/z/qabGrdvPq

`-std=c++1z` set `__cplusplus` to `201406L` in Clang 4. It was changed to 
`201703L` in 
https://github.com/llvm/llvm-project/commit/4b0cad0bb8731409c181f9a2cc9d266bb08321f9
 (Clang 5). We need to remove the `#if` condition to test corresponding 
behaviour in Clang 4.

Do I need to add this note in test file?

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


[clang] [Clang][NFC] Add test for CWG2285 "Issues with structured bindings" (PR #126421)

2025-02-10 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/126421

>From 92c075ab44bd85550fb3f63c36bd67d41821f385 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 10 Feb 2025 00:34:51 +0800
Subject: [PATCH 1/2] Add test for cwg2285

---
 clang/lib/Sema/SemaDeclCXX.cpp |  7 +--
 clang/test/CXX/drs/cwg22xx.cpp | 18 ++
 clang/www/cxx_dr_status.html   |  2 +-
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0cf02fe6407c24c..7cc67598e4c819f 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -733,8 +733,11 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
   }
 
   if (!TemplateParamLists.empty()) {
-// FIXME: There's no rule against this, but there are also no rules that
-// would actually make it usable, so we reject it for now.
+// C++17 [temp]/1:
+//   A template defines a family of class, functions, or variables, or an
+//   alias for a family of types.
+//
+// Structured bindings are not included.
 Diag(TemplateParamLists.front()->getTemplateLoc(),
  diag::err_decomp_decl_template);
 return nullptr;
diff --git a/clang/test/CXX/drs/cwg22xx.cpp b/clang/test/CXX/drs/cwg22xx.cpp
index d93070ef3804dd9..62988e35b963741 100644
--- a/clang/test/CXX/drs/cwg22xx.cpp
+++ b/clang/test/CXX/drs/cwg22xx.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
 
 
 namespace cwg2211 { // cwg2211: 8
@@ -196,6 +196,16 @@ void g() {
 #endif
 } // namespace cwg2277
 
+namespace cwg2285 { // cwg2285: 4
+#if __cplusplus >= 201703L
+  void test() {
+using T = int[1];
+auto [a] = T{a};
+// since-cxx17-error@-1 {{binding 'a' cannot appear in the initializer of 
its own decomposition declaration}}
+  }
+#endif
+} // namespace cwg2285
+
 namespace cwg2292 { // cwg2292: 9
 #if __cplusplus >= 201103L
   template using id = T;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 69ddd5e58b921a8..3fae1c6c6a0620d 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13537,7 +13537,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2285.html";>2285
 CD5
 Issues with structured bindings
-Unknown
+Clang 4
   
   
 https://cplusplus.github.io/CWG/issues/2286.html";>2286

>From 17f8c3b237e57463aa6a25b4876b1a75fec6481a Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 10 Feb 2025 20:02:54 +0800
Subject: [PATCH 2/2] Modify comment mentioned in cwg2285

---
 clang/test/Parser/cxx1z-decomposition.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Parser/cxx1z-decomposition.cpp 
b/clang/test/Parser/cxx1z-decomposition.cpp
index acf3f99069185bc..2b65e77fcd42ce6 100644
--- a/clang/test/Parser/cxx1z-decomposition.cpp
+++ b/clang/test/Parser/cxx1z-decomposition.cpp
@@ -136,7 +136,7 @@ namespace MultiDeclarator {
 
 namespace Template {
   int n[3];
-  // FIXME: There's no actual rule against this...
+  // Structured binding template is not allowed.
   template auto [a, b, c] = n; // expected-error {{decomposition 
declaration template not supported}}
 }
 

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


[clang] [clang-tools-extra] [Clang] Warning as error Array Comparisons from C++26 (PR #118872)

2024-12-06 Thread Yanzuo Liu via cfe-commits


@@ -10274,6 +10274,11 @@ def warn_array_comparison : Warning<
   "to compare array addresses, use unary '+' to decay operands to pointers">,
   InGroup>;
 
+def warn_array_comparison_cxx26 : Warning<
+  "comparison between two arrays compare their addresses not their contents; "

zwuis wrote:

I would prefer "not allowed" instead of "ill-formed".

Example:
 
https://github.com/llvm/llvm-project/blob/02ad623bb560afa1a789b49f715c9a0e48ea9b16/clang/include/clang/Basic/DiagnosticSemaKinds.td#L665-L667

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


[clang] [Clang] Warning as error Array Comparisons from C++26 (PR #118872)

2024-12-05 Thread Yanzuo Liu via cfe-commits


@@ -239,7 +239,7 @@ C++2c implementation status
  
   Remove Deprecated Array Comparisons from C++26
   https://wg21.link/P2865R6";>P2865R6
-  No
+  Clang 20

zwuis wrote:

```suggestion
  Clang 20
```


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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s

zwuis wrote:

> I think this test should go in `clang/test/Sema/conditional-expr.c` and we 
> should add a section of the GNU extension there.
> 
> I am also a bit concerned that we don't have a specific set of sema tests for 
> the GNU form of the conditional expression. So it makes me much left 
> confident that we will catch any breaks with this change.

I copied most test cases from 'clang/test/Sema/conditional-expr.c' and 
'clang/test/SemaCXX/conditional-expr.cpp' to new files, and modified them to 
FNU extension form.

Please let me know if the test cases still should be merged into one file or we 
need other test cases.

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


[clang] [Clang][Sema] Do not perform type conversion before calculating result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/108837

>From 7e5f88c322852939ae68c65f6adf4a5d2973d095 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 21:50:11 +0800
Subject: [PATCH 1/3] Fix computing result type of conditional operand

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  4 +---
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 19 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/conditional-gnu-ext.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17ec1fe0b946de..db8a7568a12114 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,6 +389,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fixed a bug in computing result type of conditional operator with omitted 
middle operand
+  (a GNU extension). (#GH15998)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..8414a55e4868b9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8785,11 +8785,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
   commonExpr = result.get();
 }
 // We usually want to apply unary conversions *before* saving, except
-// in the special case of a C++ l-value conditional.
+// in the special case in C++ that operands have the same type.
 if (!(getLangOpts().CPlusPlus
   && !commonExpr->isTypeDependent()
-  && commonExpr->getValueKind() == RHSExpr->getValueKind()
-  && commonExpr->isGLValue()
   && commonExpr->isOrdinaryOrBitFieldObject()
   && RHSExpr->isOrdinaryOrBitFieldObject()
   && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
diff --git a/clang/test/SemaCXX/conditional-gnu-ext.cpp 
b/clang/test/SemaCXX/conditional-gnu-ext.cpp
new file mode 100644
index 00..83a6fff8467863
--- /dev/null
+++ b/clang/test/SemaCXX/conditional-gnu-ext.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter
+// expected-no-diagnostics
+
+/*
+FIXME: Support constexpr
+
+constexpr int evaluate_once(int x) {
+  return (++x) ? : 10;
+}
+static_assert(evaluate_once(0) == 1, "");
+*/
+
+namespace GH15998 {
+  enum E { Zero, One };
+  E test(E e) {
+return e ? : One;
+  }
+}

>From 447c8b9c6e957308c9ff62e8c83b15b12f7fc1cb Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 23:05:50 +0800
Subject: [PATCH 2/3] Format code

---
 clang/lib/Sema/SemaExpr.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8414a55e4868b9..c232d40ca31ac6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8786,11 +8786,10 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
 }
 // We usually want to apply unary conversions *before* saving, except
 // in the special case in C++ that operands have the same type.
-if (!(getLangOpts().CPlusPlus
-  && !commonExpr->isTypeDependent()
-  && commonExpr->isOrdinaryOrBitFieldObject()
-  && RHSExpr->isOrdinaryOrBitFieldObject()
-  && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
+if (!(getLangOpts().CPlusPlus && !commonExpr->isTypeDependent() &&
+  commonExpr->isOrdinaryOrBitFieldObject() &&
+  RHSExpr->isOrdinaryOrBitFieldObject() &&
+  Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
   ExprResult commonRes = UsualUnaryConversions(commonExpr);
   if (commonRes.isInvalid())
 return ExprError();

>From 4c3dbacae0c8935384e1bfd39bf1397d5a81ad1d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Sun, 12 Jan 2025 18:50:29 +0800
Subject: [PATCH 3/3] Fix previously undiscovered case and address review
 feedbacks

'conditional-gnu-exp.cpp' is mainly copied and modified from 
'conditional-expr.cpp'
'conditional-gnu-ext.c' is mainly copied and modified from 'conditional-expr.c'
---
 clang/lib/Sema/SemaExpr.cpp|  12 +-
 clang/test/CXX/drs/cwg5xx.cpp  |  12 +
 clang/test/Sema/conditional-expr.c |   2 -
 clang/test/Sema/conditional-gnu-ext.c  | 111 ++
 clang/test/SemaCXX/conditional-expr.cpp|  24 --
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 442 -
 6 files changed, 563 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/Sema/conditional-gnu-ext.c

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index

[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter

zwuis wrote:

> Should run with BOTH constexpr interpreters.

Sorry I don't understand the meaning. Could you give an example?

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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits


@@ -8785,14 +8785,11 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
   commonExpr = result.get();
 }
 // We usually want to apply unary conversions *before* saving, except
-// in the special case of a C++ l-value conditional.
-if (!(getLangOpts().CPlusPlus
-  && !commonExpr->isTypeDependent()
-  && commonExpr->getValueKind() == RHSExpr->getValueKind()
-  && commonExpr->isGLValue()

zwuis wrote:

> So I don't see how losing the above two value kind exceptions fix this? Can 
> you explain this better?

I have updated the description of this PR. Please let me know if it isn't still 
clear enough.

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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/108837

>From 7e5f88c322852939ae68c65f6adf4a5d2973d095 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 21:50:11 +0800
Subject: [PATCH 1/3] Fix computing result type of conditional operand

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  4 +---
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 19 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/conditional-gnu-ext.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17ec1fe0b946de..db8a7568a12114 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,6 +389,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fixed a bug in computing result type of conditional operator with omitted 
middle operand
+  (a GNU extension). (#GH15998)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..8414a55e4868b9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8785,11 +8785,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
   commonExpr = result.get();
 }
 // We usually want to apply unary conversions *before* saving, except
-// in the special case of a C++ l-value conditional.
+// in the special case in C++ that operands have the same type.
 if (!(getLangOpts().CPlusPlus
   && !commonExpr->isTypeDependent()
-  && commonExpr->getValueKind() == RHSExpr->getValueKind()
-  && commonExpr->isGLValue()
   && commonExpr->isOrdinaryOrBitFieldObject()
   && RHSExpr->isOrdinaryOrBitFieldObject()
   && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
diff --git a/clang/test/SemaCXX/conditional-gnu-ext.cpp 
b/clang/test/SemaCXX/conditional-gnu-ext.cpp
new file mode 100644
index 00..83a6fff8467863
--- /dev/null
+++ b/clang/test/SemaCXX/conditional-gnu-ext.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter
+// expected-no-diagnostics
+
+/*
+FIXME: Support constexpr
+
+constexpr int evaluate_once(int x) {
+  return (++x) ? : 10;
+}
+static_assert(evaluate_once(0) == 1, "");
+*/
+
+namespace GH15998 {
+  enum E { Zero, One };
+  E test(E e) {
+return e ? : One;
+  }
+}

>From 447c8b9c6e957308c9ff62e8c83b15b12f7fc1cb Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 23:05:50 +0800
Subject: [PATCH 2/3] Format code

---
 clang/lib/Sema/SemaExpr.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8414a55e4868b9..c232d40ca31ac6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8786,11 +8786,10 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
 }
 // We usually want to apply unary conversions *before* saving, except
 // in the special case in C++ that operands have the same type.
-if (!(getLangOpts().CPlusPlus
-  && !commonExpr->isTypeDependent()
-  && commonExpr->isOrdinaryOrBitFieldObject()
-  && RHSExpr->isOrdinaryOrBitFieldObject()
-  && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
+if (!(getLangOpts().CPlusPlus && !commonExpr->isTypeDependent() &&
+  commonExpr->isOrdinaryOrBitFieldObject() &&
+  RHSExpr->isOrdinaryOrBitFieldObject() &&
+  Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
   ExprResult commonRes = UsualUnaryConversions(commonExpr);
   if (commonRes.isInvalid())
 return ExprError();

>From 4c3dbacae0c8935384e1bfd39bf1397d5a81ad1d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Sun, 12 Jan 2025 18:50:29 +0800
Subject: [PATCH 3/3] Fix previously undiscovered case and address review
 feedbacks

'conditional-gnu-exp.cpp' is mainly copied and modified from 
'conditional-expr.cpp'
'conditional-gnu-ext.c' is mainly copied and modified from 'conditional-expr.c'
---
 clang/lib/Sema/SemaExpr.cpp|  12 +-
 clang/test/CXX/drs/cwg5xx.cpp  |  12 +
 clang/test/Sema/conditional-expr.c |   2 -
 clang/test/Sema/conditional-gnu-ext.c  | 111 ++
 clang/test/SemaCXX/conditional-expr.cpp|  24 --
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 442 -
 6 files changed, 563 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/Sema/conditional-gnu-ext.c

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index

[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-12 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

> I'm also concerned about the constexpr support being 'FIXME', it seems that 
> this should just 'work' unless something odd is happening.

Sorry I forgot the restriction of constexpr function in C++11. Fixed.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-21 Thread Yanzuo Liu via cfe-commits


@@ -5321,6 +5321,59 @@ class BuiltinBitCastExpr final
   }
 };
 
+// Represents an unexpanded pack where the list of expressions are
+// known. These are used when structured bindings introduce a pack.
+class ResolvedUnexpandedPackExpr final
+: public Expr,
+  private llvm::TrailingObjects {

zwuis wrote:

Can we store `BindingDecl *` in trailing objects like `FunctionParmPackExpr`?

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


[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

2025-01-28 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/124793

In my PR #102581, elements of structured bindings is copy-initialized. They 
should be direct-initialized because the form of the initializer of the whole 
structured bindings is direct-list-initialization.

[[dcl.struct.bind]/1](https://eel.is/c++draft/dcl.struct.bind#1.sentence-8):
> ... and each element is copy-initialized or direct-initialized from the 
> corresponding element of the assignment-expression as specified by the form 
> of the initializer. ...

```cpp
int arr[2]{};
// elements of `[a, b]` should be direct-initialized
auto [a, b]{arr};
```

>From 16596add29b63ee0282e026dec7b1d5946863113 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Wed, 29 Jan 2025 00:38:15 +0800
Subject: [PATCH] Fix wrong initialization kind

---
 clang/lib/Sema/SemaInit.cpp|  5 +++--
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 21 ++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf4222056..5552fce55f1310 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4861,8 +4861,9 @@ static void TryListInitialization(Sema &S,
 S.Context.hasSameUnqualifiedType(SubInit[0]->getType(), DestType) 
&&
 "Deduced to other type?");
 TryArrayCopy(S,
- InitializationKind::CreateCopy(Kind.getLocation(),
-InitList->getLBraceLoc()),
+ InitializationKind::CreateDirect(Kind.getLocation(),
+  InitList->getLBraceLoc(),
+  
InitList->getRBraceLoc()),
  Entity, SubInit[0], DestType, Sequence,
  TreatUnavailableAsInvalid);
 if (Sequence)
diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index a8914fe4e9cd82..b3d98e44990f61 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -200,38 +200,37 @@ namespace lambdas {
 
 namespace by_value_array_copy {
   struct explicit_copy {
-explicit_copy() = default; // expected-note 2{{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
-explicit explicit_copy(const explicit_copy&) = default; // expected-note 
2{{explicit constructor is not a candidate}}
+explicit_copy() = default; // expected-note {{candidate constructor not 
viable: requires 0 arguments, but 1 was provided}}
+explicit explicit_copy(const explicit_copy&) = default; // expected-note 
{{explicit constructor is not a candidate}}
   };
 
   constexpr int direct_initialization_for_elements() {
 explicit_copy ec_arr[2];
 auto [a1, b1](ec_arr);
+auto [a2, b2]{ec_arr};
 
 int arr[3]{1, 2, 3};
-auto [a2, b2, c2](arr);
+auto [a3, b3, c3](arr);
+auto [a4, b4, c4]{arr}; // GH31813
 arr[0]--;
-return a2 + b2 + c2 + arr[0];
+return a3 + b3 + c3 + a4 + b4 + c4 + arr[0];
   }
-  static_assert(direct_initialization_for_elements() == 6);
+  static_assert(direct_initialization_for_elements() == 12);
 
   constexpr int copy_initialization_for_elements() {
 int arr[2]{4, 5};
 auto [a1, b1] = arr;
-auto [a2, b2]{arr}; // GH31813
 arr[0] = 0;
-return a1 + b1 + a2 + b2 + arr[0];
+return a1 + b1 + arr[0];
   }
-  static_assert(copy_initialization_for_elements() == 18);
+  static_assert(copy_initialization_for_elements() == 9);
 
   void copy_initialization_for_elements_with_explicit_copy_ctor() {
 explicit_copy ec_arr[2];
 auto [a1, b1] = ec_arr; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
-auto [a2, b2]{ec_arr}; // expected-error {{no matching constructor for 
initialization of 'explicit_copy[2]'}}
 
 // Test prvalue
 using T = explicit_copy[2];
-auto [a3, b3] = T{};
-auto [a4, b4]{T{}};
+auto [a2, b2] = T{};
   }
 } // namespace by_value_array_copy

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


[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

2025-01-28 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Release note is not needed if this PR is cherry-picked to `release/20.x` branch.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-21 Thread Yanzuo Liu via cfe-commits


@@ -5321,6 +5321,59 @@ class BuiltinBitCastExpr final
   }
 };
 
+// Represents an unexpanded pack where the list of expressions are
+// known. These are used when structured bindings introduce a pack.
+class ResolvedUnexpandedPackExpr final
+: public Expr,
+  private llvm::TrailingObjects {

zwuis wrote:

> ... `BindingPackExpr`?

This is what I think: using `BindingPackExpr` and modifying it when 
implementing other features (member packs etc).



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


[clang] [Clang][Sema] Do not perform type conversion before computing result type of `x ? : y` in C++ (PR #108837)

2025-01-14 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis updated 
https://github.com/llvm/llvm-project/pull/108837

>From 7e5f88c322852939ae68c65f6adf4a5d2973d095 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 21:50:11 +0800
Subject: [PATCH 1/4] Fix computing result type of conditional operand

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  4 +---
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 19 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/conditional-gnu-ext.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17ec1fe0b946de..db8a7568a12114 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,6 +389,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fixed a bug in computing result type of conditional operator with omitted 
middle operand
+  (a GNU extension). (#GH15998)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..8414a55e4868b9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8785,11 +8785,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
   commonExpr = result.get();
 }
 // We usually want to apply unary conversions *before* saving, except
-// in the special case of a C++ l-value conditional.
+// in the special case in C++ that operands have the same type.
 if (!(getLangOpts().CPlusPlus
   && !commonExpr->isTypeDependent()
-  && commonExpr->getValueKind() == RHSExpr->getValueKind()
-  && commonExpr->isGLValue()
   && commonExpr->isOrdinaryOrBitFieldObject()
   && RHSExpr->isOrdinaryOrBitFieldObject()
   && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
diff --git a/clang/test/SemaCXX/conditional-gnu-ext.cpp 
b/clang/test/SemaCXX/conditional-gnu-ext.cpp
new file mode 100644
index 00..83a6fff8467863
--- /dev/null
+++ b/clang/test/SemaCXX/conditional-gnu-ext.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter
+// expected-no-diagnostics
+
+/*
+FIXME: Support constexpr
+
+constexpr int evaluate_once(int x) {
+  return (++x) ? : 10;
+}
+static_assert(evaluate_once(0) == 1, "");
+*/
+
+namespace GH15998 {
+  enum E { Zero, One };
+  E test(E e) {
+return e ? : One;
+  }
+}

>From 447c8b9c6e957308c9ff62e8c83b15b12f7fc1cb Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 16 Sep 2024 23:05:50 +0800
Subject: [PATCH 2/4] Format code

---
 clang/lib/Sema/SemaExpr.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8414a55e4868b9..c232d40ca31ac6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8786,11 +8786,10 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation 
QuestionLoc,
 }
 // We usually want to apply unary conversions *before* saving, except
 // in the special case in C++ that operands have the same type.
-if (!(getLangOpts().CPlusPlus
-  && !commonExpr->isTypeDependent()
-  && commonExpr->isOrdinaryOrBitFieldObject()
-  && RHSExpr->isOrdinaryOrBitFieldObject()
-  && Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
+if (!(getLangOpts().CPlusPlus && !commonExpr->isTypeDependent() &&
+  commonExpr->isOrdinaryOrBitFieldObject() &&
+  RHSExpr->isOrdinaryOrBitFieldObject() &&
+  Context.hasSameType(commonExpr->getType(), RHSExpr->getType( {
   ExprResult commonRes = UsualUnaryConversions(commonExpr);
   if (commonRes.isInvalid())
 return ExprError();

>From 4c3dbacae0c8935384e1bfd39bf1397d5a81ad1d Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Sun, 12 Jan 2025 18:50:29 +0800
Subject: [PATCH 3/4] Fix previously undiscovered case and address review
 feedbacks

'conditional-gnu-exp.cpp' is mainly copied and modified from 
'conditional-expr.cpp'
'conditional-gnu-ext.c' is mainly copied and modified from 'conditional-expr.c'
---
 clang/lib/Sema/SemaExpr.cpp|  12 +-
 clang/test/CXX/drs/cwg5xx.cpp  |  12 +
 clang/test/Sema/conditional-expr.c |   2 -
 clang/test/Sema/conditional-gnu-ext.c  | 111 ++
 clang/test/SemaCXX/conditional-expr.cpp|  24 --
 clang/test/SemaCXX/conditional-gnu-ext.cpp | 442 -
 6 files changed, 563 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/Sema/conditional-gnu-ext.c

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index

[clang] [lldb] [clang][DebugInfo] Expand detection of structured bindings to account for std::get free function (PR #122265)

2025-01-10 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Do we need a test case about explicit object member function? i.e.
```cpp
template int get(this triple);
template<> int get<0>(this triple t) { return /* ... */; }
```

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-15 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-15 Thread Yanzuo Liu via cfe-commits


@@ -104,7 +104,6 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
   case Decl::Binding:
   case Decl::UnresolvedUsingIfExists:
   case Decl::HLSLBuffer:
-llvm_unreachable("Declaration should not be in declstmts!");

zwuis wrote:

Can we move some `case`s after this statement instead of removing `unreachable`?

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-15 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis commented:

FYI Clang Static Analyzer (I built this branch locally) crashes when running 
with 'clang/test/SemaCXX/cxx2c-binding-pack.cpp'. My test command is 
`path/to/build/bin/clang-tidy --checks=clang-static-analyzer-core.BitwiseShift 
another/path/to/SemaCXX/cxx2c-binding-pack.cpp`.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-15 Thread Yanzuo Liu via cfe-commits


@@ -237,7 +237,7 @@ bool Decl::isTemplateParameterPack() const {
 }
 
 bool Decl::isParameterPack() const {
-  if (const auto *Var = dyn_cast(this))
+  if (const auto *Var = dyn_cast(this))

zwuis wrote:

My idea about this part of changes is adding `BindingDecl::isParameterPack()` 
and
```cpp
if (const auto *BD = dyn_cast(this))
  return BD->isParameterPack();
```
rather than changing `VarDecl::isParameterPack()` to 
`ValueDecl::isParameterPack()`. WDYT?

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-15 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-15 Thread Yanzuo Liu via cfe-commits

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


[clang] [Clang][NFC] Add test for CWG2285 "Issues with structured bindings" (PR #126421)

2025-02-09 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/126421

The resolution of [CWG2285](https://wg21.link/cwg2285) adds the point of 
declaration of a structured binding, and was implemented in 
https://github.com/llvm/llvm-project/commit/bdb84f374cde7736ca68d5db2c2ecf5468346710
 .

Drive-by changes: modify comment mentioned in CWG2285.

>From 92c075ab44bd85550fb3f63c36bd67d41821f385 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 10 Feb 2025 00:34:51 +0800
Subject: [PATCH] Add test for cwg2285

---
 clang/lib/Sema/SemaDeclCXX.cpp |  7 +--
 clang/test/CXX/drs/cwg22xx.cpp | 18 ++
 clang/www/cxx_dr_status.html   |  2 +-
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0cf02fe6407c24c..7cc67598e4c819f 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -733,8 +733,11 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
   }
 
   if (!TemplateParamLists.empty()) {
-// FIXME: There's no rule against this, but there are also no rules that
-// would actually make it usable, so we reject it for now.
+// C++17 [temp]/1:
+//   A template defines a family of class, functions, or variables, or an
+//   alias for a family of types.
+//
+// Structured bindings are not included.
 Diag(TemplateParamLists.front()->getTemplateLoc(),
  diag::err_decomp_decl_template);
 return nullptr;
diff --git a/clang/test/CXX/drs/cwg22xx.cpp b/clang/test/CXX/drs/cwg22xx.cpp
index d93070ef3804dd9..62988e35b963741 100644
--- a/clang/test/CXX/drs/cwg22xx.cpp
+++ b/clang/test/CXX/drs/cwg22xx.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions 
-pedantic-errors
 
 
 namespace cwg2211 { // cwg2211: 8
@@ -196,6 +196,16 @@ void g() {
 #endif
 } // namespace cwg2277
 
+namespace cwg2285 { // cwg2285: 4
+#if __cplusplus >= 201703L
+  void test() {
+using T = int[1];
+auto [a] = T{a};
+// since-cxx17-error@-1 {{binding 'a' cannot appear in the initializer of 
its own decomposition declaration}}
+  }
+#endif
+} // namespace cwg2285
+
 namespace cwg2292 { // cwg2292: 9
 #if __cplusplus >= 201103L
   template using id = T;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 69ddd5e58b921a8..3fae1c6c6a0620d 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13537,7 +13537,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2285.html";>2285
 CD5
 Issues with structured bindings
-Unknown
+Clang 4
   
   
 https://cplusplus.github.io/CWG/issues/2286.html";>2286

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


[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)

2025-02-14 Thread Yanzuo Liu via cfe-commits


@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const {
   return VD;
 }
 
-llvm::ArrayRef BindingDecl::getBindingPackExprs() const {
+llvm::ArrayRef BindingDecl::getBindingPackDecls() const {
   assert(Binding && "expecting a pack expr");
-  auto *RP = cast(Binding);
-  return RP->getExprs();
+  auto *FP = cast(Binding);
+  ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr;
+  assert((!First || isa(*First)) && "expecting a BindingDecl");
+  return llvm::ArrayRef(
+  reinterpret_cast(First), FP->getNumExpansions());

zwuis wrote:

Can we use `static_cast` here?

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-09 Thread Yanzuo Liu via cfe-commits

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-09 Thread Yanzuo Liu via cfe-commits


@@ -8361,6 +8361,17 @@ class ExprEvaluatorBase
 return false;
 }
 
+// If an assertion fails during constant evaluation, give a specific note 
explaining that
+if (FD->getName() == "__assert_fail") {

zwuis wrote:

The name of corresponding function in Microsoft CRT is `_wassert`.

Can you handle this case?

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-09 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis commented:

Thank you for the patch! You should add a release note in 
clang/docs/ReleaseNotes.rst so that users can know the improvement.

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


[clang] [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (PR #129198)

2025-03-05 Thread Yanzuo Liu via cfe-commits

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


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


[clang] [Clang][NFC] Add test for CWG2289 "Uniqueness of structured binding names" (PR #131054)

2025-03-12 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/131054

The resolution of [CWG2289](https://wg21.link/cwg2289) added that the name of a 
structured binding must be unique in its declarative region, and was 
implemented in 
https://github.com/llvm/llvm-project/commit/bdb84f374cde7736ca68d5db2c2ecf5468346710
 .

>From 4b21efb204f8bc0523b162dc22fc490d45cb52f3 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Thu, 13 Mar 2025 10:00:37 +0800
Subject: [PATCH] Add test for cwg2289

---
 clang/test/CXX/drs/cwg22xx.cpp | 12 
 clang/www/cxx_dr_status.html   |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg22xx.cpp b/clang/test/CXX/drs/cwg22xx.cpp
index 8c8ad9f7f74ee..e9dd07c8ebf87 100644
--- a/clang/test/CXX/drs/cwg22xx.cpp
+++ b/clang/test/CXX/drs/cwg22xx.cpp
@@ -207,6 +207,18 @@ namespace cwg2285 { // cwg2285: 4
 #endif
 } // namespace cwg2285
 
+namespace cwg2289 { // cwg2289: 4
+// Note: Clang 4 implements this DR but it set a wrong value of `__cplusplus`
+#if __cplusplus >= 201703L
+  void test() {
+struct A { int x; } a; // #cwg2289-A
+auto &[A] = a;
+// since-cxx17-error@-1 {{redefinition of 'A'}}
+//   since-cxx17-note@#cwg2289-A {{previous definition is here}}
+  }
+#endif
+} // namespace cwg2289
+
 namespace cwg2292 { // cwg2292: 9
 #if __cplusplus >= 201103L
   template using id = T;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index b7888d2365acc..e727d127c4384 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13561,7 +13561,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2289.html";>2289
 CD5
 Uniqueness of structured binding names
-Unknown
+Clang 4
   
   
 https://cplusplus.github.io/CWG/issues/2290.html";>2290

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


[clang] [Clang][NFC] Add test for CWG2289 "Uniqueness of structured binding names" (PR #131054)

2025-03-19 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

> "Declarative region" is clearly pre-P1787R6 wording. Can you find the wording 
> in the current draft that covers this?

Yes. I have updated the description of this PR.

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


[clang] [Clang] Introduce a trait to determine the structure binding size (PR #131515)

2025-03-19 Thread Yanzuo Liu via cfe-commits


@@ -1642,6 +1661,56 @@ void 
Sema::CheckCompleteDecompositionDeclaration(DecompositionDecl *DD) {
 DD->setInvalidDecl();
 }
 
+std::optional Sema::GetDecompositionElementCount(QualType T,
+   SourceLocation Loc) 
{
+  const ASTContext &Ctx = getASTContext();
+  assert(!T->isDependentType());
+
+  Qualifiers Quals;
+  QualType Unqual = Context.getUnqualifiedArrayType(T, Quals);
+  Quals.removeCVRQualifiers();
+  T = Context.getQualifiedType(Unqual, Quals);
+
+  if (auto *CAT = Ctx.getAsConstantArrayType(T))
+return CAT->getSize().getZExtValue();
+  if (auto *VT = T->getAs())
+return VT->getNumElements();
+  if (T->getAs())
+return 2;
+
+  llvm::APSInt TupleSize(Ctx.getTypeSize(Ctx.getSizeType()));
+  switch (isTupleLike(*this, Loc, T, TupleSize)) {
+  case IsTupleLike::Error:
+return {};
+  case IsTupleLike::TupleLike:
+return TupleSize.getExtValue();
+  case IsTupleLike::NotTupleLike:
+break;
+  }
+
+  const CXXRecordDecl *OrigRD = T->getAsCXXRecordDecl();
+  if (!OrigRD || OrigRD->isUnion())
+return std::nullopt;
+
+  if (RequireCompleteType(Loc, T, diag::err_incomplete_type))
+return std::nullopt;
+
+  CXXCastPath BasePath;
+  DeclAccessPair BasePair =
+  findDecomposableBaseClass(*this, Loc, OrigRD, BasePath);
+  const auto *RD = cast_or_null(BasePair.getDecl());
+  if (!RD)
+return std::nullopt;
+
+  unsigned NumFields = llvm::count_if(
+  RD->fields(), [](FieldDecl *FD) { return !FD->isUnnamedBitField(); });
+
+  if (CheckMemberDecompositionFields(*this, Loc, OrigRD, T, BasePair))
+return true;

zwuis wrote:

`return true` or `return std::nullopt`?

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


[clang] [clang][ExtractAPI] emit correct spelling for type aliases (PR #134007)

2025-04-04 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -extract-api --pretty-sgf 
--emit-sgf-symbol-labels-for-testing \
+// RUN:   --product-name=TypeAlias -triple arm64-apple-macosx -x c++-header %s 
-o %t/type-alias.symbols.json -verify
+
+// RUN: FileCheck %s --input-file %t/type-alias.symbols.json --check-prefix 
MYALIAS
+using MyAlias = int;
+//MYALIAS-LABEL "!testLabel": "c:@MYALIAS"
+//MYALIAS:   "accessLevel": "public",
+//MYALIAS:   "declarationFragments": [
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "keyword",
+//MYALIAS-NEXT:  "spelling": "using"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": " "
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "identifier",
+//MYALIAS-NEXT:  "spelling": "MyAlias"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": " = "
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "typeIdentifier",
+//MYALIAS-NEXT:  "preciseIdentifier": "c:I",
+//MYALIAS-NEXT:  "spelling": "int"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": ";"
+//MYALIAS-NEXT:}
+//MYALIAS:   "kind": {
+//MYALIAS-NEXT:  "displayName": "Type Alias",
+//MYALIAS-NEXT:  "identifier": "c++.typealias"
+//MYALIAS:   names": {
+//MYALIAS-NEXT:"navigator": [
+//MYALIAS-NEXT:  {
+//MYALIAS-NEXT:"kind": "identifier",
+//MYALIAS-NEXT:"spelling": "MyAlias"
+//MYALIAS-NEXT:  }
+//MYALIAS-NEXT:],
+//MYALIAS-NEXT:  "subHeading": [
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "identifier",
+//MYALIAS-NEXT:  "spelling": "MyAlias"
+//MYALIAS-NEXT:}
+//MYALIAS-NEXT:],
+//MYALIAS-NEXT:"title": "MyAlias"
+//MYALIAS:   "pathComponents": [
+//MYALIAS-NEXT:"MyAlias"
+//MYALIAS-NEXT:  ]
+
+// expected-no-diagnostics

zwuis wrote:

nit: add a new line charactor at end of file

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Yanzuo Liu via cfe-commits


@@ -32,6 +32,26 @@ enum E2 : S::I { e };
 #endif
 } // namespace cwg2516
 
+namespace cwg2517 { // cwg2517: 21
+#if __cplusplus >= 202302L

zwuis wrote:

IIUC this DR is applied to C++20.

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-26 Thread Yanzuo Liu via cfe-commits


@@ -32,6 +32,26 @@ enum E2 : S::I { e };
 #endif
 } // namespace cwg2516
 
+namespace cwg2517 { // cwg2517: 21
+#if __cplusplus >= 202302L

zwuis wrote:

The resolution of defect reports is applied to all C++ standard verions where 
the issue exists unless specified (e.g. [CWG2237](https://wg21.link/cwg2237)). 
You can visit  to see the meaning of the 
issue status code.

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


[clang] [Clang][Sema] Handle invalid variable template specialization whose type depends on itself (PR #134522)

2025-04-06 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/134522

Fixes #51347 

>From ccab3dc1f18ffeda9acb07c0bd5f80f65cc788b9 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Sun, 6 Apr 2025 15:06:56 +0800
Subject: [PATCH] Handle invalid variable template specialization whose type
 depends on itself

---
 clang/docs/ReleaseNotes.rst|  2 ++
 .../include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaTemplate.cpp|  7 +++
 .../SemaTemplate/instantiate-var-template.cpp  | 18 ++
 4 files changed, 30 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5217e04b5e83f..9e0fe8a94729b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -414,6 +414,8 @@ Bug Fixes to C++ Support
 - Clang now issues an error when placement new is used to modify a 
const-qualified variable
   in a ``constexpr`` function. (#GH131432)
 - Clang now emits a warning when class template argument deduction for alias 
templates is used in C++17. (#GH133806)
+- No longer crashes when instantiating invalid variable template specialization
+  whose type depends on itself. (#GH51347)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 393bfecf9a36b..0c1da40dba388 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5259,6 +5259,9 @@ def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<
   "extraneous 'template<>' in declaration of %0 %1">;
+def err_var_template_spec_type_depends_on_self : Error<
+  "the type of variable template specialization %0 declared with deduced type "
+  "%1 depends on itself">;
 
 def warn_unqualified_call_to_std_cast_function : Warning<
   "unqualified call to '%0'">, InGroup>;
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 153f44f8ec67a..ce54dbbb3b9fe 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4377,6 +4377,13 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
   if (VarTemplateSpecializationDecl *Spec =
   Template->findSpecialization(CTAI.CanonicalConverted, InsertPos)) {
 checkSpecializationReachability(TemplateNameLoc, Spec);
+if (Spec->getType()->isUndeducedType()) {
+  // We are substituting the initializer of this variable template
+  // specialization.
+  Diag(TemplateNameLoc, diag::err_var_template_spec_type_depends_on_self)
+  << Spec << Spec->getType();
+  return true;
+}
 // If we already have a variable template specialization, return it.
 return Spec;
   }
diff --git a/clang/test/SemaTemplate/instantiate-var-template.cpp 
b/clang/test/SemaTemplate/instantiate-var-template.cpp
index 60d3bd3b59f53..34a1b9710814b 100644
--- a/clang/test/SemaTemplate/instantiate-var-template.cpp
+++ b/clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -47,3 +47,21 @@ namespace InvalidInsertPos {
   template<> int v;
   int k = v;
 }
+
+namespace GH51347 {
+  template 
+  auto p = p; // expected-error {{the type of variable template 
specialization 'p'}}
+
+  auto x = p; // expected-note {{in instantiation of variable template 
specialization 'GH51347::p'}}
+}
+
+namespace GH97881_comment {
+  template 
+  auto g = sizeof(g);
+  // expected-error@-1 {{the type of variable template specialization 
'g'}}
+  // expected-note@-2 {{in instantiation of variable template specialization 
'GH97881_comment::g'}}
+
+  void test() {
+(void)sizeof(g); // expected-note {{in instantiation of variable 
template specialization 'GH97881_comment::g'}}
+  }
+}

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


[clang] [Clang][NFC] Add test for CWG2289 "Uniqueness of structured binding names" (PR #131054)

2025-04-05 Thread Yanzuo Liu via cfe-commits

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


[clang] [clang] Check `std::initializer_list` more strictly (PR #133822)

2025-04-05 Thread Yanzuo Liu via cfe-commits


@@ -2590,8 +2590,14 @@ def err_auto_non_deduced_not_alone : Error<
 def err_implied_std_initializer_list_not_found : Error<
   "cannot deduce type of initializer list because std::initializer_list was "
   "not found; include ">;
-def err_malformed_std_initializer_list : Error<
-  "std::initializer_list must be a class template with a single type 
parameter">;
+def err_malformed_std_initializer_list
+: Error<"std::initializer_list %select{"
+"must have exactly one template parameter|"
+"cannot have associated constraints|"
+"must have a type template parameter|"
+"cannot have default template arguments|"
+"cannot be a variadic template|"
+"must be a class template}0">;

zwuis wrote:

Can you use "enum_select" format instead of "select" format?

See 
.

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


[clang] [clang] Check `std::initializer_list` more strictly (PR #133822)

2025-04-05 Thread Yanzuo Liu via cfe-commits

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


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


[clang] [clang] Implement CWG2815 (PR #132778)

2025-04-05 Thread Yanzuo Liu via cfe-commits


@@ -47,6 +47,28 @@ void f() {
 #endif
 } // namespace cwg2813
 
+namespace cwg2815 { // cwg2815: 21
+#if __cpp_noexcept_function_type >= 201510

zwuis wrote:

I'm not sure if checking values of feature test macros is better then checking 
the value of `__cplusplus`, but the rest of the file checks the value of 
`__cplusplus`. CC @Endilll 

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