[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-05 Thread Yuanfang Chen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92f4bf268998: Fix aggregate CTAD with string literals adding 
extra const (authored by MitalAshok, committed by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 https://cplusplus.github.io/CWG/issues/2681.html;>2681
 DR
 Deducing member array type from string literal
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/2682.html;>2682
Index: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
===
--- clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -198,22 +198,22 @@
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
   // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
-  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
-  // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
-  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
-  // CHECK:   |-TemplateArgument type 'const char'
-  // CHECK:   | `-QualType {{.*}} 'const char' const
-  // CHECK:   |   `-BuiltinType {{.*}} 'char'
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (const T (&)[N]) -> A'
+  // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
+  // CHECK:   |-TemplateArgument type 'char'
+  // CHECK:   | `-BuiltinType {{.*}} 'char'
   // CHECK:   |-TemplateArgument integral 5
   // CHECK:   `-ParmVarDecl {{.*}} 'const char (&)[5]'
-  // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A' dependent 
trailing_return cdecl
+  // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A' 
dependent trailing_return cdecl
   // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
   // CHECK: | `-CXXRecord {{.*}} 'A'
-  // CHECK: `-LValueReferenceType {{.*}} 'T (&)[N]' dependent
-  // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
-  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
-  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
+  // CHECK: `-LValueReferenceType {{.*}} 'const T (&)[N]' dependent
+  // CHECK:   `-QualType {{.*}} 'const T[N]' const
+  // CHECK: `-DependentSizedArrayType {{.*}} 'T[N]' dependent
+  // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK:   `-DeclRefExpr {{.*}} 'size_t':'unsigned{{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned{{.*}}'
 }
 
 namespace BraceElision {
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -126,3 +126,27 @@
 brachiosaur |= neck;// OK
 }
 }
+
+namespace dr2681 { // dr2681: 17
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 

[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen accepted this revision.
ychen added a comment.
This revision is now accepted and ready to land.

LGTM. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 536648.
MitalAshok edited the summary of this revision.
MitalAshok added a comment.

Add status for CWG2681 and fixed aggregate-deduction-candidate test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 https://cplusplus.github.io/CWG/issues/2681.html;>2681
 DR
 Deducing member array type from string literal
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/2682.html;>2682
Index: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
===
--- clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -198,22 +198,22 @@
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
   // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
-  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
-  // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
-  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
-  // CHECK:   |-TemplateArgument type 'const char'
-  // CHECK:   | `-QualType {{.*}} 'const char' const
-  // CHECK:   |   `-BuiltinType {{.*}} 'char'
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (const T (&)[N]) -> A'
+  // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
+  // CHECK:   |-TemplateArgument type 'char'
+  // CHECK:   | `-BuiltinType {{.*}} 'char'
   // CHECK:   |-TemplateArgument integral 5
   // CHECK:   `-ParmVarDecl {{.*}} 'const char (&)[5]'
-  // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A' dependent 
trailing_return cdecl
+  // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A' 
dependent trailing_return cdecl
   // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
   // CHECK: | `-CXXRecord {{.*}} 'A'
-  // CHECK: `-LValueReferenceType {{.*}} 'T (&)[N]' dependent
-  // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
-  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
-  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
+  // CHECK: `-LValueReferenceType {{.*}} 'const T (&)[N]' dependent
+  // CHECK:   `-QualType {{.*}} 'const T[N]' const
+  // CHECK: `-DependentSizedArrayType {{.*}} 'T[N]' dependent
+  // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK:   `-DeclRefExpr {{.*}} 'size_t':'unsigned{{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned{{.*}}'
 }
 
 namespace BraceElision {
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -126,3 +126,27 @@
 brachiosaur |= neck;// OK
 }
 }
+
+namespace dr2681 { // dr2681: 17
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 https://cplusplus.github.io/CWG/issues/2681.html;>2681
 DR
 Deducing member array type from 

[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

`clang/test/SemaTemplate/aggregate-deduction-candidate.cpp` seems need updates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

Thanks for catching this. The change LGTM. I think this is 
https://wg21.link/cwg2681. Could you please move the test to 
`clang/test/CXX/drs/dr26xx.cpp` and keep only these tests that are in the DR? 
Then you could run `clang/www/make_cxx_dr_status` to update 
`clang/www/cxx_dr_status.html`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok created this revision.
Herald added a project: All.
MitalAshok edited the summary of this revision.
MitalAshok added reviewers: ychen, aaron.ballman, cor3ntin.
MitalAshok added a subscriber: cfe-commits.
MitalAshok retitled this revision from "Fix CTAD with string literals adding 
extra const" to "Fix aggregate CTAD with string literals adding extra const".
MitalAshok added inline comments.
MitalAshok published this revision for review.
Herald added a project: clang.



Comment at: clang/lib/Sema/SemaInit.cpp:10707
 //   if e_i is of array type and x_i is a bstring-literal, T_i is an
 //   lvalue reference to the const-qualified declared type of e_i and
 // C++ [over.match.class.deduct]p1.10:

The "const-qualified" here was missing


Missing a `withConst`, so when deducing from a string literal, a `const` is 
erroneously added to the deduced type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154301

Files:
  clang/lib/Sema/SemaInit.cpp
  
clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp


Index: 
clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
===
--- /dev/null
+++ 
clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+
+template
+struct K {
+  char array[N];
+};
+K k = { "abc" };
+static_assert(__is_same(decltype(k), K<4>));
+
+template
+struct L {
+  const T array[N];
+};
+L l = { "abc" };
+static_assert(__is_same(decltype(l), L));
+
+template
+struct M {
+  T array[sizeof(T) == 0 ? 4 : 4];
+};
+M m = { "abc" };
+static_assert(__is_same(decltype(m), M));
+
+/*
+template
+struct N {
+  T array[4];
+};
+// The C99 extension, brace elision for designated initializers,
+// makes `T = const char*` viable, and that is used instead
+N n = { .array = "abc" };
+static_assert(__is_same(decltype(n), N));
+ */
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;


Index: clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
===
--- /dev/null
+++ clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction guide}}
+
+template
+struct K {
+  char array[N];
+};
+K k = { "abc" };
+static_assert(__is_same(decltype(k), K<4>));
+
+template
+struct L {
+  const T array[N];
+};
+L l = { "abc" };
+static_assert(__is_same(decltype(l), L));
+
+template
+struct M {
+  T array[sizeof(T) == 0 ? 4 : 4];
+};
+M m = { "abc" };
+static_assert(__is_same(decltype(m), M));
+
+/*
+template
+struct N {
+  T array[4];
+};
+// The C99 extension, brace elision for designated initializers,
+// makes `T = const char*` viable, and that is used instead
+N n = { .array = "abc" };
+static_assert(__is_same(decltype(n), N));
+ */
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+