public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3996] c++: argument order in a variadic type trait intrinsic
@ 2021-09-30 21:51 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-09-30 21:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fdf8d5bc5b52bd733037dbeeff442c59f8aa765b

commit r12-3996-gfdf8d5bc5b52bd733037dbeeff442c59f8aa765b
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Sep 30 17:29:18 2021 -0400

    c++: argument order in a variadic type trait intrinsic
    
    When parsing a variadic type trait intrinsic, we build up the list of
    trailing arguments in reverse, but we neglect to reverse the list to
    the true order afterwards.  This causes us to confuse the meaning of
    e.g. __is_xible(x, y, z) vs __is_xible(x, z, y).
    
    Note that this bug doesn't affect the library traits because they pass a
    pack expansion as the single trailing argument to __is_xible, which gets
    expanded in the correct order by tsubst_tree_list.
    
    gcc/cp/ChangeLog:
    
            * parser.c (cp_parser_trait_expr): Call nreverse on the reversed
            list of trailing arguments.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/ext/is_constructible6.C: New test.

Diff:
---
 gcc/cp/parser.c                              |  1 +
 gcc/testsuite/g++.dg/ext/is_constructible6.C | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 8430445ef8c..04f5a24cc03 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10832,6 +10832,7 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword)
 	    return error_mark_node;
 	  type2 = tree_cons (NULL_TREE, elt, type2);
 	}
+      type2 = nreverse (type2);
     }
 
   location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location;
diff --git a/gcc/testsuite/g++.dg/ext/is_constructible6.C b/gcc/testsuite/g++.dg/ext/is_constructible6.C
new file mode 100644
index 00000000000..7fce153fa75
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_constructible6.C
@@ -0,0 +1,10 @@
+// Verify we respect the order of trailing arguments passed to
+// __is_constructible.
+
+struct A { };
+struct B { };
+struct C { C(A, B); };
+
+extern int n[true];
+extern int n[ __is_constructible(C, A, B)];
+extern int n[!__is_constructible(C, B, A)];


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-30 21:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30 21:51 [gcc r12-3996] c++: argument order in a variadic type trait intrinsic Patrick Palka

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).