]> gcc.gnu.org Git - gcc.git/commitdiff
c++: Diagnose bare parameter packs in bitfield widths [PR99745]
authorJakub Jelinek <jakub@redhat.com>
Thu, 25 Mar 2021 20:06:09 +0000 (21:06 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 20 Apr 2021 23:28:18 +0000 (01:28 +0200)
The following invalid tests ICE because we don't diagnose (and drop) bare
parameter packs in bitfield widths.

2021-03-25  Jakub Jelinek  <jakub@redhat.com>

PR c++/99745
* decl2.c (grokbitfield): Diagnose bitfields containing bare parameter
packs and don't set DECL_BIT_FIELD_REPRESENTATIVE in that case.

* g++.dg/cpp0x/variadic181.C: New test.

(cherry picked from commit f8780caf07340f5d5e55cf5fb1b2be07cabab1ea)

gcc/cp/decl2.c
gcc/testsuite/g++.dg/cpp0x/variadic181.C [new file with mode: 0644]

index a15bb3c45cc48d45e5667b7257a2f0ab565f8280..672bd62f1ce75ee16301379f704c8e597f87d168 100644 (file)
@@ -1098,7 +1098,7 @@ grokbitfield (const cp_declarator *declarator,
          && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
        error ("width of bit-field %qD has non-integral type %qT", value,
               TREE_TYPE (width));
-      else
+      else if (!check_for_bare_parameter_packs (width))
        {
          /* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
             check_bitfield_decl picks it from there later and sets DECL_SIZE
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic181.C b/gcc/testsuite/g++.dg/cpp0x/variadic181.C
new file mode 100644 (file)
index 0000000..0bb6fe7
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/99745
+// { dg-do compile { target c++11 } }
+
+template <typename... Ts>
+struct S { int a : sizeof(Ts); };      // { dg-error "parameter packs not expanded with '\.\.\.':" }
+S<int> s;                              // { dg-message "'Ts'" "" { target *-*-* } .-1 }
+template <int... Ns>
+struct T { int a : Ns; };              // { dg-error "parameter packs not expanded with '\.\.\.':" }
+T<0> t;                                        // { dg-message "'Ns'" "" { target *-*-* } .-1 }
This page took 0.085525 seconds and 5 git commands to generate.