public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template
@ 2013-09-30 20:17 reichelt at gcc dot gnu.org
  2013-10-01 10:47 ` [Bug c++/58583] " mpolacek at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: reichelt at gcc dot gnu.org @ 2013-09-30 20:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

            Bug ID: 58583
           Summary: [c++11] ICE with invalid non-static data member
                    initialization in template
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: reichelt at gcc dot gnu.org

The following invalid code snippet (compiled with "-std=c++0x") is wrongly
accepted since GCC 4.7.0 (when non-static data member initializers were
introduced):

==============================
template<int N> struct A
{
  A* p = new A<N>;
};
==============================

Even instantiating A<0> doesn't produce an error.
However, without template the code is rejected correctly.

A slightly modified code snippet triggers an ICE:

==============================
struct B
{
  template<int N> struct A
  {
    A* p = new A<0>;
  };
};
==============================

bug.cc: In constructor 'constexpr B::A<0>::A()':
bug.cc:3:26: internal compiler error: in tsubst_copy, at cp/pt.c:12810
   template<int N> struct A
                          ^
0x5bbd53 tsubst_copy
        ../../gcc/gcc/cp/pt.c:12810
0x59aa12 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc/gcc/cp/pt.c:14855
0x69636c perform_member_init
        ../../gcc/gcc/cp/init.c:538
0x69636c emit_mem_initializers(tree_node*)
        ../../gcc/gcc/cp/init.c:1093
0x6a0a2e synthesize_method(tree_node*)
        ../../gcc/gcc/cp/method.c:796
0x617659 mark_used(tree_node*, int)
        ../../gcc/gcc/cp/decl2.c:4714
0x54889b build_over_call
        ../../gcc/gcc/cp/call.c:7116
0x54477e build_new_method_call_1
        ../../gcc/gcc/cp/call.c:7813
0x54477e build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ../../gcc/gcc/cp/call.c:7883
0x5456f2 build_special_member_call(tree_node*, tree_node*, vec<tree_node*,
va_gc, vl_embed>**, tree_node*, int, int)
        ../../gcc/gcc/cp/call.c:7440
0x699086 build_new_1
        ../../gcc/gcc/cp/init.c:2761
0x699086 build_new(vec<tree_node*, va_gc, vl_embed>**, tree_node*, tree_node*,
vec<tree_node*, va_gc, vl_embed>**, int, int)
        ../../gcc/gcc/cp/init.c:3001
0x645ad2 cp_parser_new_expression
        ../../gcc/gcc/cp/parser.c:7139
0x646097 cp_parser_unary_expression
        ../../gcc/gcc/cp/parser.c:6910
0x646b4f cp_parser_binary_expression
        ../../gcc/gcc/cp/parser.c:7701
0x64700f cp_parser_assignment_expression
        ../../gcc/gcc/cp/parser.c:7937
0x647466 cp_parser_assignment_expression
        ../../gcc/gcc/cp/parser.c:7987
0x647466 cp_parser_constant_expression
        ../../gcc/gcc/cp/parser.c:8197
0x648a36 cp_parser_late_parse_one_default_arg
        ../../gcc/gcc/cp/parser.c:23055
0x637c35 cp_parser_late_parsing_nsdmi
        ../../gcc/gcc/cp/parser.c:23109
Please submit a full bug report, [etc.]


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
@ 2013-10-01 10:47 ` mpolacek at gcc dot gnu.org
  2013-10-04  9:08 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-10-01 10:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The ICE started with r180707.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
  2013-10-01 10:47 ` [Bug c++/58583] " mpolacek at gcc dot gnu.org
@ 2013-10-04  9:08 ` paolo.carlini at oracle dot com
  2013-12-30 21:58 ` reichelt at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-04  9:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-10-04
             Blocks|                            |58616
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
  2013-10-01 10:47 ` [Bug c++/58583] " mpolacek at gcc dot gnu.org
  2013-10-04  9:08 ` paolo.carlini at oracle dot com
@ 2013-12-30 21:58 ` reichelt at gcc dot gnu.org
  2014-08-13 18:03 ` reichelt at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: reichelt at gcc dot gnu.org @ 2013-12-30 21:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

--- Comment #2 from Volker Reichelt <reichelt at gcc dot gnu.org> ---
The second testcase is now also wrongly accepted, due to the fix for PR57887.
However, the following testcase still crashes with almost the same stacktrace:

===========================
template<int> struct A
{
  int i = (A<0>(), 0);
};
===========================

bug.cc: In constructor 'constexpr A<0>::A()':
bug.cc:1:22: internal compiler error: in tsubst_copy, at cp/pt.c:12863
 template<int> struct A
                      ^
0x5f62a3 tsubst_copy
        ../../gcc/gcc/cp/pt.c:12863
0x5d35f2 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc/gcc/cp/pt.c:15083
0x6d8523 perform_member_init
        ../../gcc/gcc/cp/init.c:537
0x6d8523 emit_mem_initializers(tree_node*)
        ../../gcc/gcc/cp/init.c:1096
0x6e310e synthesize_method(tree_node*)
        ../../gcc/gcc/cp/method.c:799
0x6532f4 mark_used(tree_node*, int)
        ../../gcc/gcc/cp/decl2.c:4779
0x580359 build_over_call
        ../../gcc/gcc/cp/call.c:7119
0x57bd35 build_new_method_call_1
        ../../gcc/gcc/cp/call.c:7818
0x57bd35 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ../../gcc/gcc/cp/call.c:7888
0x57ce17 build_special_member_call(tree_node*, tree_node*, vec<tree_node*,
va_gc, vl_embed>**, tree_node*, int, int)
        ../../gcc/gcc/cp/call.c:7444
0x6d5697 build_value_init(tree_node*, int)
        ../../gcc/gcc/cp/init.c:345
0x61ee49 build_functional_cast(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/typeck2.c:1858
0x5d364e tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc/gcc/cp/pt.c:14053
0x5d77a5 fold_non_dependent_expr_sfinae(tree_node*, int)
        ../../gcc/gcc/cp/pt.c:5111
0x5d77e9 build_non_dependent_expr(tree_node*)
        ../../gcc/gcc/cp/pt.c:21234
0x6a93e7 build_x_compound_expr(unsigned int, tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/typeck.c:6136
0x6847fb cp_parser_expression
        ../../gcc/gcc/cp/parser.c:8294
0x67bb3f cp_parser_primary_expression
        ../../gcc/gcc/cp/parser.c:4279
0x67e5da cp_parser_postfix_expression
        ../../gcc/gcc/cp/parser.c:5969
0x681698 cp_parser_unary_expression
        ../../gcc/gcc/cp/parser.c:7170
Please submit a full bug report, [etc.]


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-12-30 21:58 ` reichelt at gcc dot gnu.org
@ 2014-08-13 18:03 ` reichelt at gcc dot gnu.org
  2015-05-27 23:19 ` nathan at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: reichelt at gcc dot gnu.org @ 2014-08-13 18:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

--- Comment #3 from Volker Reichelt <reichelt at gcc dot gnu.org> ---
Since May all three testcases ICE on trunk.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-08-13 18:03 ` reichelt at gcc dot gnu.org
@ 2015-05-27 23:19 ` nathan at gcc dot gnu.org
  2015-06-16  2:00 ` nathan at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: nathan at gcc dot gnu.org @ 2015-05-27 23:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

Nathan Sidwell <nathan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |nathan at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |nathan at gcc dot gnu.org


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2015-05-27 23:19 ` nathan at gcc dot gnu.org
@ 2015-06-16  2:00 ` nathan at gcc dot gnu.org
  2015-06-16  2:03 ` nathan at gcc dot gnu.org
  2015-10-05 19:54 ` miyuki at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: nathan at gcc dot gnu.org @ 2015-06-16  2:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

--- Comment #4 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Author: nathan
Date: Tue Jun 16 01:59:55 2015
New Revision: 224502

URL: https://gcc.gnu.org/viewcvs?rev=224502&root=gcc&view=rev
Log:
        cp/
        PR c++/58583
        * cp-tree.h (DECL_INSTANTIATING_NSDMI_P): New.
        * init.c (get_nsdmi): Check for DEFAULT_ARG in template case and
        protect it from recursive instantiation.

        testsuite/
        PR c++/58583
        * g++.dg/cpp0x/nsdmi-template14.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/nsdmi-template14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2015-06-16  2:00 ` nathan at gcc dot gnu.org
@ 2015-06-16  2:03 ` nathan at gcc dot gnu.org
  2015-10-05 19:54 ` miyuki at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: nathan at gcc dot gnu.org @ 2015-06-16  2:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

Nathan Sidwell <nathan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
fixed on trunk.  Note initializers are instantiated lazily, so invalid ones may
be accepted without error, if never instantiated.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58583] [c++11] ICE with invalid non-static data member initialization in template
  2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2015-06-16  2:03 ` nathan at gcc dot gnu.org
@ 2015-10-05 19:54 ` miyuki at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-10-05 19:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58583

Mikhail Maltsev <miyuki at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |miyuki at gcc dot gnu.org
         Resolution|FIXED                       |---

--- Comment #7 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
The diagnostic differs between "--enable-checking=yes" and
"--enable-checking=release" builds:

Checking:
miyuki@gcc-build1:~$ /opt/gcc-6-latest/bin/g++ -std=c++11 ./nsdmi-template14.C
./nsdmi-template14.C:6:20: error: constructor required before non-static data
member for 'A<0>::i' has been parsed
   int i = (A<0>(), 0); // { dg-error "has been parsed" }
                    ^
./nsdmi-template14.C: In constructor 'constexpr A<0>::A()':
./nsdmi-template14.C:4:22: error: constructor required before non-static data
member for 'A<0>::i' has been parsed
 template<int> struct A // { dg-error "has been parsed" }
                      ^
./nsdmi-template14.C: At global scope:
./nsdmi-template14.C:6:20: note: synthesized method 'constexpr A<0>::A()' first
required here 
   int i = (A<0>(), 0); // { dg-error "has been parsed" }
                    ^
./nsdmi-template14.C:14:6: error: recursive instantiation of non-static data
member initializer for 'B<1>::p'
 B<1> x; // { dg-error "recursive instantiation of non-static data" }
      ^

Release:
miyuki@gcc-build1:~$ /opt/gcc-6-latest-rel/bin/g++ -std=c++11
./nsdmi-template14.C
./nsdmi-template14.C:14:6: error: recursive instantiation of non-static data
member initializer for 'B<1>::p'
 B<1> x; // { dg-error "recursive instantiation of non-static data" }
      ^

The latter obviously does not pass the test.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-05 19:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-30 20:17 [Bug c++/58583] New: [c++11] ICE with invalid non-static data member initialization in template reichelt at gcc dot gnu.org
2013-10-01 10:47 ` [Bug c++/58583] " mpolacek at gcc dot gnu.org
2013-10-04  9:08 ` paolo.carlini at oracle dot com
2013-12-30 21:58 ` reichelt at gcc dot gnu.org
2014-08-13 18:03 ` reichelt at gcc dot gnu.org
2015-05-27 23:19 ` nathan at gcc dot gnu.org
2015-06-16  2:00 ` nathan at gcc dot gnu.org
2015-06-16  2:03 ` nathan at gcc dot gnu.org
2015-10-05 19:54 ` miyuki 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).