Skip to content

Commit 66833f4

Browse files
committed
[clang] Allow parentheses around CTAD declarators
1 parent 7fa104e commit 66833f4

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ Bug Fixes to C++ Support
358358
- Fixed a Clang regression in C++20 mode where unresolved dependent call expressions were created inside non-dependent contexts (#GH122892)
359359
- Clang now emits the ``-Wunused-variable`` warning when some structured bindings are unused
360360
and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
361+
- Declarations using class template argument deduction with redundant
362+
parentheses around the declarator are no longer rejected. (#GH39811)
361363

362364
Bug Fixes to AST Handling
363365
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,10 +2612,9 @@ def err_decltype_auto_initializer_list : Error<
26122612
"cannot deduce 'decltype(auto)' from initializer list">;
26132613

26142614
// C++17 deduced class template specialization types
2615-
def err_deduced_class_template_compound_type : Error<
2616-
"cannot %select{form pointer to|form reference to|form array of|"
2617-
"form function returning|use parentheses when declaring variable with}0 "
2618-
"deduced class template specialization type">;
2615+
def err_deduced_class_template_compound_type
2616+
: Error<"cannot form %select{pointer to|reference to|array of|function "
2617+
"returning}0 deduced class template specialization type">;
26192618
def err_deduced_non_class_or_alias_template_specialization_type : Error<
26202619
"%select{<error>|function template|variable template|alias template|"
26212620
"template template parameter|concept|template}0 %1 requires template "

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,8 +4282,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
42824282

42834283
// If T is 'decltype(auto)', the only declarators we can have are parens
42844284
// and at most one function declarator if this is a function declaration.
4285-
// If T is a deduced class template specialization type, we can have no
4286-
// declarator chunks at all.
4285+
// If T is a deduced class template specialization type, only parentheses
4286+
// are allowed.
42874287
if (auto *DT = T->getAs<DeducedType>()) {
42884288
const AutoType *AT = T->getAs<AutoType>();
42894289
bool IsClassTemplateDeduction = isa<DeducedTemplateSpecializationType>(DT);
@@ -4297,11 +4297,6 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
42974297
unsigned DiagKind = 0;
42984298
switch (DeclChunk.Kind) {
42994299
case DeclaratorChunk::Paren:
4300-
// FIXME: Rejecting this is a little silly.
4301-
if (IsClassTemplateDeduction) {
4302-
DiagKind = 4;
4303-
break;
4304-
}
43054300
continue;
43064301
case DeclaratorChunk::Function: {
43074302
if (IsClassTemplateDeduction) {

clang/test/Parser/cxx1z-class-template-argument-deduction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace template_template_arg_pack {
3939
template<typename...> struct YP {};
4040

4141
struct Z { template<typename T> struct Q {}; }; // expected-note 2{{here}}
42-
42+
4343
template<typename T> using ZId = Z;
4444

4545
template<typename ...Ts> struct A {
@@ -152,7 +152,7 @@ namespace decl {
152152
A a;
153153
A b = 0;
154154
const A c = 0;
155-
A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
155+
A (parens) = 0;
156156
A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
157157
A &r = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
158158
A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
@@ -179,7 +179,7 @@ namespace typename_specifier {
179179
}
180180
typename ::A a = 0;
181181
const typename ::A b = 0;
182-
typename ::A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
182+
typename ::A (parens) = 0;
183183
typename ::A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
184184
typename ::A &r = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
185185
typename ::A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
@@ -217,7 +217,7 @@ namespace typename_specifier {
217217
}
218218

219219
namespace parenthesized {
220-
template<typename T> struct X { X(T); };
220+
template<typename T> struct X { X(T); };
221221
auto n = (X([]{}));
222222
}
223223

clang/test/SemaCXX/ctad.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s
22

3+
namespace GH39811 {
4+
5+
template<int = 0> class C {};
6+
7+
C (a);
8+
C (b) = C();
9+
C (c) {};
10+
C (((((d)))));
11+
12+
template<C (e)> class X;
13+
template<C (...f)> class Y;
14+
15+
void test() {
16+
C (g);
17+
C (h) = C();
18+
C (i) {};
19+
(void)g;
20+
(void)h;
21+
(void)i;
22+
}
23+
24+
C* (bad1); // expected-error {{cannot form pointer to deduced class template specialization type}}
25+
C (*bad2); // expected-error {{cannot form pointer to deduced class template specialization type}}
26+
27+
}
28+
329
namespace GH64347 {
430

531
template<typename X, typename Y> struct A { X x; Y y;};

0 commit comments

Comments
 (0)