Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions clang/test/CXX/drs/cwg22xx.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -196,6 +196,16 @@ void g() {
#endif
} // namespace cwg2277

namespace cwg2285 { // cwg2285: 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 4b0cad0 (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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, Clang 4 behaves as expected without #if __cplusplus.

Do I need to add this note in test file?

Yes, leave a comment somewhere that Clang 4 doesn't pass the test because of the wrong value of __cplusplus, even though it implements the DR.

#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<typename T> using id = T;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Parser/cxx1z-decomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T> auto [a, b, c] = n; // expected-error {{decomposition declaration template not supported}}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -13537,7 +13537,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2285.html">2285</a></td>
<td>CD5</td>
<td>Issues with structured bindings</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 4</td>
</tr>
<tr id="2286">
<td><a href="https://cplusplus.github.io/CWG/issues/2286.html">2286</a></td>
Expand Down