public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template
@ 2021-08-19 21:41 ed at catmur dot uk
2021-08-19 22:52 ` [Bug c++/101988] [12 Regression] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: ed at catmur dot uk @ 2021-08-19 21:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
Bug ID: 101988
Summary: Accepts invalid new-expression of array of deduced
class template
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ed at catmur dot uk
Target Milestone: ---
template<class T> struct A { A(T); };
auto p = new A[]{1};
g++
(Compiler-Explorer-Build-gcc-f0fca213bc52644ba896da622b35842a6157bd98-binutils-2.36.1)
12.0.0 20210818 (experimental) accepts (it allocates and constructs a single
`A<int>`.
gcc 11.2 and below rejects, correctly: error: creating array of 'A<...auto...>'
Per [expr.new]/2 the invented declaration should be:
A[] x{1};
which is ill-formed.
nb. clang ICEs on this (https://bugs.llvm.org/show_bug.cgi?id=51547)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
@ 2021-08-19 22:52 ` pinskia at gcc dot gnu.org
2021-08-19 22:56 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-19 22:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-08-19
Ever confirmed|0 |1
Summary|Accepts invalid |[12 Regression] Accepts
|new-expression of array of |invalid new-expression of
|deduced class template |array of deduced class
| |template
Target Milestone|--- |12.0
Keywords| |accepts-invalid
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, note doing [1] instead of [] causes GCC to reject (and clang not to
ICE either).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
2021-08-19 22:52 ` [Bug c++/101988] [12 Regression] " pinskia at gcc dot gnu.org
@ 2021-08-19 22:56 ` pinskia at gcc dot gnu.org
2021-08-19 23:01 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-19 22:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I also noticed, GCC accepts while clang rejects:
template<class T> struct A { A(T); };
auto p = new A<int>[]{A(1),A(1)};
While changing it to [2], both GCC and clang accepts it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
2021-08-19 22:52 ` [Bug c++/101988] [12 Regression] " pinskia at gcc dot gnu.org
2021-08-19 22:56 ` pinskia at gcc dot gnu.org
@ 2021-08-19 23:01 ` pinskia at gcc dot gnu.org
2021-08-19 23:11 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-19 23:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> I also noticed, GCC accepts while clang rejects:
> template<class T> struct A { A(T); };
> auto p = new A<int>[]{A(1),A(1)};
>
> While changing it to [2], both GCC and clang accepts it.
Note ICC and MSVC accepts the above so I think it is a clang bug.
Oh and GCC rejects this:
template<class T> struct A { A(T); };
auto p = new A[]{1,2};
But thinks A[] is really A:
<source>:2:21: error: class template argument deduction failed:
2 | auto p = new A[]{1,2};
| ^
<source>:2:21: error: no matching function for call to 'A(int, int)'
<source>:1:30: note: candidate: 'template<class T> A(T)-> A<T>'
1 | template<class T> struct A { A(T); };
| ^
<source>:1:30: note: template argument deduction/substitution failed:
<source>:2:21: note: candidate expects 1 argument, 2 provided
2 | auto p = new A[]{1,2};
| ^
<source>:1:26: note: candidate: 'template<class T> A(A<T>)-> A<T>'
1 | template<class T> struct A { A(T); };
| ^
<source>:1:26: note: template argument deduction/substitution failed:
<source>:2:21: note: mismatched types 'A<T>' and 'int'
2 | auto p = new A[]{1,2};
| ^
So that might get the hint of the problem.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
` (2 preceding siblings ...)
2021-08-19 23:01 ` pinskia at gcc dot gnu.org
@ 2021-08-19 23:11 ` pinskia at gcc dot gnu.org
2021-08-20 9:03 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-19 23:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Maybe related to PR 82110 but there has been other CTAD changes in GCC 12 too.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
` (3 preceding siblings ...)
2021-08-19 23:11 ` pinskia at gcc dot gnu.org
@ 2021-08-20 9:03 ` redi at gcc dot gnu.org
2021-08-20 13:57 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-20 9:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started to be accepted with r12-1933:
c++: DR2397 - auto specifier for * and & to arrays [PR100975]
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
` (4 preceding siblings ...)
2021-08-20 9:03 ` redi at gcc dot gnu.org
@ 2021-08-20 13:57 ` mpolacek at gcc dot gnu.org
2022-01-20 10:49 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-08-20 13:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
` (5 preceding siblings ...)
2021-08-20 13:57 ` mpolacek at gcc dot gnu.org
@ 2022-01-20 10:49 ` rguenth at gcc dot gnu.org
2022-01-27 13:23 ` cvs-commit at gcc dot gnu.org
2022-01-27 13:25 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-20 10:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
` (6 preceding siblings ...)
2022-01-20 10:49 ` rguenth at gcc dot gnu.org
@ 2022-01-27 13:23 ` cvs-commit at gcc dot gnu.org
2022-01-27 13:25 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-27 13:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:0c0f453c4af4880c522c8472c33eef42bee9eda1
commit r12-6894-g0c0f453c4af4880c522c8472c33eef42bee9eda1
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Jan 26 17:29:19 2022 -0500
c++: new-expr of array of deduced class tmpl [PR101988]
In r12-1933 I attempted to implement DR2397 aka allowing
int a[3];
auto (&r)[3] = a;
by removing the type_uses_auto check in create_array_type_for_decl.
That may have gone too far, because it also allows arrays of
CLASS_PLACEHOLDER_TEMPLATE and it looks like [dcl.type.class.deduct]
prohibits that: "...the declared type of the variable shall be cv T,
where T is the placeholder." However, in /2 it explicitly states that
"A placeholder for a deduced class type can also be used in the
type-specifier-seq in the new-type-id or type-id of a new-expression."
In this PR, it manifested by making us accept invalid
template<class T> struct A { A(T); };
auto p = new A[]{1};
[expr.new]/2 says that such a construct is treated as an invented
declaration of the form
A x[]{1};
but, I think, that ought to be ill-formed as per above. So this patch
sort of restores the create_array_type_for_decl check. I should mention
that the difference between [] and [1] is due to cp_parser_new_type_id:
if (*nelts == NULL_TREE)
/* Leave [] in the declarator. */;
and groktypename returning different types based on that.
PR c++/101988
gcc/cp/ChangeLog:
* decl.cc (create_array_type_for_decl): Reject forming an array of
placeholder for a deduced class type.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/class-deduction-new1.C: New test.
* g++.dg/cpp23/auto-array2.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/101988] [12 Regression] Accepts invalid new-expression of array of deduced class template
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
` (7 preceding siblings ...)
2022-01-27 13:23 ` cvs-commit at gcc dot gnu.org
@ 2022-01-27 13:25 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-01-27 13:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101988
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fixed. I've also added pretty much all of the other testcases in
this PR.
> Note ICC and MSVC accepts the above so I think it is a clang bug.
I think so too.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-01-27 13:25 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 21:41 [Bug c++/101988] New: Accepts invalid new-expression of array of deduced class template ed at catmur dot uk
2021-08-19 22:52 ` [Bug c++/101988] [12 Regression] " pinskia at gcc dot gnu.org
2021-08-19 22:56 ` pinskia at gcc dot gnu.org
2021-08-19 23:01 ` pinskia at gcc dot gnu.org
2021-08-19 23:11 ` pinskia at gcc dot gnu.org
2021-08-20 9:03 ` redi at gcc dot gnu.org
2021-08-20 13:57 ` mpolacek at gcc dot gnu.org
2022-01-20 10:49 ` rguenth at gcc dot gnu.org
2022-01-27 13:23 ` cvs-commit at gcc dot gnu.org
2022-01-27 13:25 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).