public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a
@ 2020-04-30 12:57 ppalka at gcc dot gnu.org
2020-04-30 13:08 ` [Bug c++/94885] Functional cast from int to empty class type with empty base " mpolacek at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-30 12:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Bug ID: 94885
Summary: Functional cast from int to empty class incorrectly
accepted with -std=c++2a
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ppalka at gcc dot gnu.org
Target Milestone: ---
The following testcase
template <typename T, typename = decltype(T(0))>
void foo();
struct base {};
struct derived : base {};
void
bar()
{
foo<derived>();
}
is rejected by GCC 9 (with both -std=c++17 and -std=c++2a) and rejected by GCC
10 with -std=c++17, but it's accepted by GCC 10 with -std=c++2a.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
@ 2020-04-30 13:08 ` mpolacek at gcc dot gnu.org
2020-04-30 13:14 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-30 13:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Accepted since my r10-6519-gac6eaa55a5199196ea0a25763114ce05333a14d3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
2020-04-30 13:08 ` [Bug c++/94885] Functional cast from int to empty class type with empty base " mpolacek at gcc dot gnu.org
@ 2020-04-30 13:14 ` jakub at gcc dot gnu.org
2020-04-30 13:56 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-30 13:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r10-6519-gac6eaa55a5199196ea0a25763114ce05333a14d3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
2020-04-30 13:08 ` [Bug c++/94885] Functional cast from int to empty class type with empty base " mpolacek at gcc dot gnu.org
2020-04-30 13:14 ` jakub at gcc dot gnu.org
@ 2020-04-30 13:56 ` mpolacek at gcc dot gnu.org
2020-04-30 14:17 ` [Bug c++/94885] [10 Regression] " rguenth at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-30 13:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2020-04-30
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (2 preceding siblings ...)
2020-04-30 13:56 ` mpolacek at gcc dot gnu.org
@ 2020-04-30 14:17 ` rguenth at gcc dot gnu.org
2020-04-30 15:18 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-30 14:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |10.0
Summary|Functional cast from int to |[10 Regression] Functional
|empty class type with empty |cast from int to empty
|base incorrectly accepted |class type with empty base
|with -std=c++2a |incorrectly accepted with
| |-std=c++2a
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (3 preceding siblings ...)
2020-04-30 14:17 ` [Bug c++/94885] [10 Regression] " rguenth at gcc dot gnu.org
@ 2020-04-30 15:18 ` mpolacek at gcc dot gnu.org
2020-05-01 20:36 ` [Bug c++/94885] [10/11 " cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-30 15:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
process_init_constructor_record:
1743 if (DECL_SIZE (field) && integer_zerop (DECL_SIZE (field))
1744 && !TREE_SIDE_EFFECTS (next))
1745 /* Don't add trivial initialization of an empty base/field to the
1746 constructor, as they might not be ordered the way the back-end
1747 expects. */
1748 continue;
but here the initializer was erroneous so skipping it made us accept invalid
code. Patch incoming.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10/11 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (4 preceding siblings ...)
2020-04-30 15:18 ` mpolacek at gcc dot gnu.org
@ 2020-05-01 20:36 ` cvs-commit at gcc dot gnu.org
2020-05-01 20:37 ` [Bug c++/94885] [10 " mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-01 20:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:30da2906ac521749aef8260fc1d942e62073f19d
commit r11-20-g30da2906ac521749aef8260fc1d942e62073f19d
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Apr 30 11:36:17 2020 -0400
c++: Parenthesized-init of aggregates accepts invalid code [PR94885]
Here we have (conceptually *) something like
struct B { };
struct D : B { };
D(0); // invalid
and in C++20 the ()-initialization has created a { 0 } constructor that
it tries to initialize an object of type D with. We should reject
initializing an object of type B from 0, but we wrongly accept it because
process_init_constructor_record skips initializers for empty bases/fields:
if (DECL_SIZE (field) && integer_zerop (DECL_SIZE (field))
&& !TREE_SIDE_EFFECTS (next))
/* Don't add trivial initialization of an empty base/field to the
constructor, as they might not be ordered the way the back-end
expects. */
continue;
but here 'next' was error_mark_node, returned by massage_elt_init, so we
wound up with { } which would validly value-initialize the object.
[*] Usually digest_init in build_new_method_call_1 would detect this,
but in this case the instance is is_dummy_object and we don't call
digest just yet.
PR c++/94885
* typeck2.c (process_init_constructor_record): Return
PICFLAG_ERRONEOUS
if an initializer element was erroneous.
* g++.dg/cpp2a/paren-init26.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (5 preceding siblings ...)
2020-05-01 20:36 ` [Bug c++/94885] [10/11 " cvs-commit at gcc dot gnu.org
@ 2020-05-01 20:37 ` mpolacek at gcc dot gnu.org
2020-05-07 11:56 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-01 20:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[10/11 Regression] |[10 Regression] Functional
|Functional cast from int to |cast from int to empty
|empty class type with empty |class type with empty base
|base incorrectly accepted |incorrectly accepted with
|with -std=c++2a |-std=c++2a
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (6 preceding siblings ...)
2020-05-01 20:37 ` [Bug c++/94885] [10 " mpolacek at gcc dot gnu.org
@ 2020-05-07 11:56 ` jakub at gcc dot gnu.org
2020-05-08 15:06 ` cvs-commit at gcc dot gnu.org
2020-05-08 15:08 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-07 11:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.0 |10.2
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.1 has been released.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (7 preceding siblings ...)
2020-05-07 11:56 ` jakub at gcc dot gnu.org
@ 2020-05-08 15:06 ` cvs-commit at gcc dot gnu.org
2020-05-08 15:08 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-08 15:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:ceae6a13366d9646e172fc943fe8e221b70f0920
commit r10-8124-gceae6a13366d9646e172fc943fe8e221b70f0920
Author: Marek Polacek <polacek@redhat.com>
Date: Fri May 8 11:04:29 2020 -0400
c++: Parenthesized-init of aggregates accepts invalid code [PR94885]
Here we have (conceptually *) something like
struct B { };
struct D : B { };
D(0); // invalid
and in C++20 the ()-initialization has created a { 0 } constructor that
it tries to initialize an object of type D with. We should reject
initializing an object of type B from 0, but we wrongly accept it because
process_init_constructor_record skips initializers for empty bases/fields:
if (DECL_SIZE (field) && integer_zerop (DECL_SIZE (field))
&& !TREE_SIDE_EFFECTS (next))
/* Don't add trivial initialization of an empty base/field to the
constructor, as they might not be ordered the way the back-end
expects. */
continue;
but here 'next' was error_mark_node, returned by massage_elt_init, so we
wound up with { } which would validly value-initialize the object.
[*] Usually digest_init in build_new_method_call_1 would detect this,
but in this case the instance is is_dummy_object and we don't call
digest just yet.
PR c++/94885
* typeck2.c (process_init_constructor_record): Return
PICFLAG_ERRONEOUS
if an initializer element was erroneous.
* g++.dg/cpp2a/paren-init26.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/94885] [10 Regression] Functional cast from int to empty class type with empty base incorrectly accepted with -std=c++2a
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
` (8 preceding siblings ...)
2020-05-08 15:06 ` cvs-commit at gcc dot gnu.org
@ 2020-05-08 15:08 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-08 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94885
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in 10.2 too.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-05-08 15:08 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 12:57 [Bug c++/94885] New: Functional cast from int to empty class incorrectly accepted with -std=c++2a ppalka at gcc dot gnu.org
2020-04-30 13:08 ` [Bug c++/94885] Functional cast from int to empty class type with empty base " mpolacek at gcc dot gnu.org
2020-04-30 13:14 ` jakub at gcc dot gnu.org
2020-04-30 13:56 ` mpolacek at gcc dot gnu.org
2020-04-30 14:17 ` [Bug c++/94885] [10 Regression] " rguenth at gcc dot gnu.org
2020-04-30 15:18 ` mpolacek at gcc dot gnu.org
2020-05-01 20:36 ` [Bug c++/94885] [10/11 " cvs-commit at gcc dot gnu.org
2020-05-01 20:37 ` [Bug c++/94885] [10 " mpolacek at gcc dot gnu.org
2020-05-07 11:56 ` jakub at gcc dot gnu.org
2020-05-08 15:06 ` cvs-commit at gcc dot gnu.org
2020-05-08 15:08 ` 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).