[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const
Yuanfang Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 5 11:56:07 PDT 2023
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 @@
<td><a href="https://cplusplus.github.io/CWG/issues/2681.html">2681</a></td>
<td>DR</td>
<td>Deducing member array type from string literal</td>
- <td class="none" align="center">Unknown</td>
+ <td class="unreleased" align="center">Clang 17</td>
</tr>
<tr id="2682">
<td><a href="https://cplusplus.github.io/CWG/issues/2682.html">2682</a></td>
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 <deduction guide for A>
// CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 0 index 1 N
- // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for A> 'auto (T (&)[N]) -> A<T, N>'
- // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
- // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for A> 'auto (const char (&)[5]) -> Array::A<const char, 5>'
- // CHECK: |-TemplateArgument type 'const char'
- // CHECK: | `-QualType {{.*}} 'const char' const
- // CHECK: | `-BuiltinType {{.*}} 'char'
+ // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for A> 'auto (const T (&)[N]) -> A<T, N>'
+ // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+ // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for A> 'auto (const char (&)[5]) -> Array::A<char, 5>'
+ // CHECK: |-TemplateArgument type 'char'
+ // CHECK: | `-BuiltinType {{.*}} 'char'
// CHECK: |-TemplateArgument integral 5
// CHECK: `-ParmVarDecl {{.*}} 'const char (&)[5]'
- // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A<T, N>' dependent trailing_return cdecl
+ // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A<T, N>' dependent trailing_return cdecl
// CHECK: |-InjectedClassNameType {{.*}} 'A<T, N>' 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<class T, size_t N>
+struct H {
+ T array[N];
+};
+template<class T, size_t N>
+struct I {
+ volatile T array[N];
+};
+template<size_t N>
+struct J { // expected-note 3{{candidate}}
+ unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H<char, 4>)); // Not H<const char, 4>
+static_assert(__is_same(decltype(i), I<char, 4>));
+
+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<StringLiteral>(
ListInit->getInit(I)->IgnoreParenImpCasts()))
- ElementTypes[I] = Context.getLValueReferenceType(ElementTypes[I]);
+ ElementTypes[I] =
+ Context.getLValueReferenceType(ElementTypes[I].withConst());
}
llvm::FoldingSetNodeID ID;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154301.537456.patch
Type: text/x-patch
Size: 4615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/de742e4f/attachment.bin>
More information about the cfe-commits
mailing list