public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function
@ 2021-11-24 7:57 hewillk at gmail dot com
2021-11-24 9:38 ` [Bug c++/103401] " redi at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: hewillk at gmail dot com @ 2021-11-24 7:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
Bug ID: 103401
Summary: gcc accepts decltype(auto(0)) as the parameter of the
function
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
It seems that gcc should not accept this strange syntax, although I don't know
why f has two template parameters..
void f(decltype(auto(0))) { }
int main() {
f<int,int>(0);
}
https://godbolt.org/z/PaevrsrE8
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
@ 2021-11-24 9:38 ` redi at gcc dot gnu.org
2021-11-24 9:40 ` [Bug c++/103401] [11/12 Regression] " redi at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-24 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2021-11-24
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
2021-11-24 9:38 ` [Bug c++/103401] " redi at gcc dot gnu.org
@ 2021-11-24 9:40 ` redi at gcc dot gnu.org
2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-24 9:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|gcc accepts |[11/12 Regression] gcc
|decltype(auto(0)) as the |accepts decltype(auto(0))
|parameter of the function |as the parameter of the
| |function
Target Milestone|--- |11.3
CC| |mpolacek at gcc dot gnu.org
Known to work| |10.3.0
Known to fail| |11.2.1, 12.0
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started to be accepted with r11-1913
"c++: Better diagnostic for decltype(auto) in C++11 [PR96103]"
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
2021-11-24 9:38 ` [Bug c++/103401] " redi at gcc dot gnu.org
2021-11-24 9:40 ` [Bug c++/103401] [11/12 Regression] " redi at gcc dot gnu.org
@ 2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
2021-11-25 0:56 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-24 14:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
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
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Mine then.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
` (2 preceding siblings ...)
2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
@ 2021-11-25 0:56 ` mpolacek at gcc dot gnu.org
2021-11-25 2:44 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-25 0:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is trickier than it seemed.
void f(decltype(auto(0))) { }
is actually valid in C++23 (probably) since auto(x) is supported. So I think
it's essentially like
void f(int) { }
The r11-1913 change is OK: we need to make sure that we see '(auto)' after
decltype to go ahead with 'decltype(auto)'.
I think we shouldn't be calling synthesize_implicit_template_parm for auto(x)
in a parameter-list.
More tests:
void f1 (decltype(auto(0)));
void f2 (decltype(auto{0}));
void f3 (int = auto(42));
void f4 (int = auto{42});
void f5 (decltype(auto(0)) = auto(42));
// Careful about just checking ( after auto:
void f6 (auto (x));
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
` (3 preceding siblings ...)
2021-11-25 0:56 ` mpolacek at gcc dot gnu.org
@ 2021-11-25 2:44 ` mpolacek at gcc dot gnu.org
2021-12-09 16:49 ` cvs-commit at gcc dot gnu.org
2021-12-09 17:26 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-25 2:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think the patch might be just:
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7508,6 +7508,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool
address_p, bool cast_p,
looking at a functional cast. We could also be looking at
an id-expression. So, we try the functional cast, and if
that doesn't work we fall back to the primary-expression. */
+ auto cleanup = make_temp_override
+ (parser->auto_is_implicit_function_template_parm_p, false);
cp_parser_parse_tentatively (parser);
/* Look for the simple-type-specifier. */
++parser->prevent_constrained_type_specifiers;
Until C++23 auto(x), we didn't have to think about auto in a
parameter-decl-clause all that much I suspect.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
` (4 preceding siblings ...)
2021-11-25 2:44 ` mpolacek at gcc dot gnu.org
@ 2021-12-09 16:49 ` cvs-commit at gcc dot gnu.org
2021-12-09 17:26 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-09 16:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
--- Comment #5 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:6a071b2d40a1078b4029c2b77ef29ffca4e7050c
commit r12-5860-g6a071b2d40a1078b4029c2b77ef29ffca4e7050c
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Nov 25 09:08:03 2021 -0500
c++: Handle auto(x) in parameter-declaration-clause [PR103401]
In C++23, auto(x) is valid, so decltype(auto(x)) should also be valid,
so
void f(decltype(auto(0)));
should be just as
void f(int);
but currently, everytime we see 'auto' in a parameter-declaration-clause,
we try to synthesize_implicit_template_parm for it, creating a new template
parameter list. The code above actually has us calling s_i_t_p twice;
once from cp_parser_decltype_expr -> cp_parser_postfix_expression which
fails and then again from cp_parser_decltype_expr -> cp_parser_expression.
So it looks like we have f<auto, auto> and we accept ill-formed code.
This shows that we need to be more careful about synthesizing the
implicit template parameter. [dcl.spec.auto.general] says that "A
placeholder-type-specifier of the form type-constraintopt auto can be
used as a decl-specifier of the decl-specifier-seq of a
parameter-declaration of a function declaration or lambda-expression..."
so this patch turns off auto_is_... after we've parsed the
decl-specifier-seq.
That doesn't quite cut it yet though, because we also need to handle an
auto nested in the decl-specifier:
void f(decltype(new auto{0}));
therefore the cp_parser_decltype change.
To accept "sizeof(auto{10})", the cp_parser_type_id_1 hunk only gives a
hard error when we're not parsing tentatively.
The cp_parser_parameter_declaration hunk broke lambda-generic-85713-2.C but
I think the error we issue with this patch is in fact correct, and clang++
agrees.
The r11-1913 change is OK: we need to make sure that we see '(auto)' after
decltype to go ahead with 'decltype(auto)'.
PR c++/103401
gcc/cp/ChangeLog:
* parser.c (cp_parser_decltype): Clear
auto_is_implicit_function_template_parm_p.
(cp_parser_type_id_1): Give errors only when
!cp_parser_simulate_error.
(cp_parser_parameter_declaration): Clear
auto_is_implicit_function_template_parm_p after parsing the
decl-specifier-seq.
(cp_parser_sizeof_operand): Clear
auto_is_implicit_function_template_parm_p.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/lambda-generic-85713-2.C: Add dg-error.
* g++.dg/cpp1y/pr60054.C: Adjust dg-error.
* g++.dg/cpp1y/pr60332.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979-2.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979-3.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979.C: Likewise.
* g++.dg/cpp23/auto-fncast7.C: New test.
* g++.dg/cpp23/auto-fncast8.C: New test.
* g++.dg/cpp23/auto-fncast9.C: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
` (5 preceding siblings ...)
2021-12-09 16:49 ` cvs-commit at gcc dot gnu.org
@ 2021-12-09 17:26 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-12-09 17:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103401
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fixed now.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-12-09 17:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 7:57 [Bug c++/103401] New: gcc accepts decltype(auto(0)) as the parameter of the function hewillk at gmail dot com
2021-11-24 9:38 ` [Bug c++/103401] " redi at gcc dot gnu.org
2021-11-24 9:40 ` [Bug c++/103401] [11/12 Regression] " redi at gcc dot gnu.org
2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
2021-11-25 0:56 ` mpolacek at gcc dot gnu.org
2021-11-25 2:44 ` mpolacek at gcc dot gnu.org
2021-12-09 16:49 ` cvs-commit at gcc dot gnu.org
2021-12-09 17:26 ` 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).