Created attachment 38497 [details] Reproducer gcc (GCC) 6.1.1 20160510 (Red Hat 6.1.1-2) The attached code does not compile under g++ 6. It works fine under 5.3 (with -std=gnu++14). Removing "template <typename T>, or converting the array to be an array of unsigned (instead of array of struct) hides the problem.
Created attachment 38498 [details] Slightly simpler reproducer (no std::atomic)
I believe this started with r233126.
There is code to handle this case in instantiate_class_template_1 but it's not quite correct. It assumes that the the array element type has been completed which in this case isn't a safe assumption. Let me fix this. A slightly simpler test case is below: $ cat xx.cpp && gcc -S -Wall -Wextra -Wpedantic xx.cpp template <typename> struct container { struct elem { unsigned u; }; struct incomplete { int x; elem array[]; }; }; unsigned f (container<void>::incomplete* i) { return i->array [0].u; } xx.cpp: In instantiation of ‘struct container<void>::incomplete’: xx.cpp:15:11: required from here xx.cpp:9:16: error: ‘container< <template-parameter-1-1> >::incomplete::array’ has incomplete type elem array[]; ^ xx.cpp:9:16: error: invalid use of array with unspecified bounds
Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2016-05/msg01427.html
Author: msebor Date: Tue May 24 20:29:36 2016 New Revision: 236664 URL: https://gcc.gnu.org/viewcvs?rev=236664&root=gcc&view=rev Log: PR c++/71147 - [6 Regression] Flexible array member wrongly rejected in template gcc/ChangeLog: 2016-05-24 Martin Sebor <msebor@redhat.com> PR c++/71147 * gcc/tree.h (complete_or_array_type_p): New inline function. gcc/testsuite/ChangeLog: 2016-05-24 Martin Sebor <msebor@redhat.com> PR c++/71147 * g++.dg/ext/flexary16.C: New test. gcc/cp/ChangeLog: 2016-05-24 Martin Sebor <msebor@redhat.com> PR c++/71147 * decl.c (layout_var_decl, grokdeclarator): Use complete_or_array_type_p. * pt.c (instantiate_class_template_1): Try to complete the element type of a flexible array member. (can_complete_type_without_circularity): Handle arrays of unknown bound. * typeck.c (complete_type): Also complete the type of the elements of arrays with an unspecified bound. Added: trunk/gcc/testsuite/g++.dg/ext/flexary16.C Modified: trunk/gcc/ChangeLog trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/cp/pt.c trunk/gcc/cp/typeck.c trunk/gcc/testsuite/ChangeLog trunk/gcc/tree.h
Author: msebor Date: Wed May 25 16:01:24 2016 New Revision: 236729 URL: https://gcc.gnu.org/viewcvs?rev=236729&root=gcc&view=rev Log: PR c++/71147 - [6 Regression] Flexible array member wrongly rejected in template gcc/ChangeLog: 2016-05-24 Martin Sebor <msebor@redhat.com> PR c++/71147 * gcc/tree.h (complete_or_array_type_p): New inline function. gcc/testsuite/ChangeLog: 2016-05-24 Martin Sebor <msebor@redhat.com> PR c++/71147 * g++.dg/ext/flexary16.C: New test. gcc/cp/ChangeLog: 2016-05-24 Martin Sebor <msebor@redhat.com> PR c++/71147 * decl.c (layout_var_decl, grokdeclarator): Use complete_or_array_type_p. * pt.c (instantiate_class_template_1): Try to complete the element type of a flexible array member. (can_complete_type_without_circularity): Handle arrays of unknown bound. * typeck.c (complete_type): Also complete the type of the elements of arrays with an unspecified bound. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/ext/flexary16.C Modified: branches/gcc-6-branch/gcc/ChangeLog branches/gcc-6-branch/gcc/cp/ChangeLog branches/gcc-6-branch/gcc/cp/decl.c branches/gcc-6-branch/gcc/cp/pt.c branches/gcc-6-branch/gcc/cp/typeck.c branches/gcc-6-branch/gcc/testsuite/ChangeLog branches/gcc-6-branch/gcc/tree.h
Fixed on trunk (r236664) and 6-branch (r236729).
(In reply to Martin Sebor from comment #7) > Fixed on trunk (r236664) and 6-branch (r236729). https://github.com/google/re2/issues/102 reported this for g++ (GCC) 6.1.1 20160707. The 6-20160707 snapshot was taken at gcc-6-branch revision 238150, so I guess that it would have included your fix. Is it possible that the bug is not completely fixed yet? (My apologies in advance if I'm barking up the wrong tree!) P.S. Thank you for redirecting me here from bug 70932. :)
The test case from comment 4 on bug 70932 fails due to this bug. But looking at the error in comment 3 more closely I see "unbekannte Feldgröße in »delete«" which with some help from Google Translate does look like the same error as in bug 70932. Sorry for the confusion!