public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62212] New: ICE compiling template function with array reference parameter whose size depends on a template parameter
@ 2014-08-20 20:54 lhyatt at gmail dot com
  2014-12-03 19:05 ` [Bug c++/62212] " lhyatt at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lhyatt at gmail dot com @ 2014-08-20 20:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 62212
           Summary: ICE compiling template function with array reference
                    parameter whose size depends on a template parameter
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lhyatt at gmail dot com

I get an ICE in gcc 4.8.1 and also on 4.9 when compiling the code below.
Doesn't matter the optimization level or what -std=:

============================

typedef int my_int;

template<typename T>
struct X {
    enum {value = 1};
};

template<typename T>
void f(const my_int(&)[X<T>::value]);

int main() {
    const my_int a[1] = {};
    f<void>(a);
}

============================

$ g++ -v -c t.cpp
Using built-in specs.
COLLECT_GCC=/usr/local/gcc48/bin/g++
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-threads=posix --enable-__cxa_atexit
--prefix=/usr/local/gcc-4.8.1
Thread model: posix
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/cc1plus -quiet
-v -D_GNU_SOURCE t.cpp -quiet -dumpbase t.cpp -mtune=generic -march=x86-64
-auxbase t -version -o /tmp/ccbr6RST.s
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 2.4.2-p1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1

/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu

/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include
 /usr/local/include
 /usr/local/gcc-4.8.1/include
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 2.4.2-p1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9381368e685e312c931bb6a2db2d568c
t.cpp: In instantiation of 'void f(const my_int (&)[X<T>::value]) [with T =
void; my_int = int]':
t.cpp:13:15:   required from here
t.cpp:9:6: internal compiler error: Segmentation fault
 void f(const my_int(&)[X<T>::value]);
      ^
0x89ffef crash_signal
    ../.././gcc/toplev.c:332
0x72a8c7 fold_convert_loc(unsigned int, tree_node*, tree_node*)
    ../.././gcc/fold-const.c:1879
0x72e648 associate_trees
    ../.././gcc/fold-const.c:891
0x71d534 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
    ../.././gcc/fold-const.c:10589
0x72768a fold_build2_stat_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
    ../.././gcc/fold-const.c:14877
0x7195ce fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
    ../.././gcc/fold-const.c:9934
0x72768a fold_build2_stat_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
    ../.././gcc/fold-const.c:14877
0x89ac30 layout_type(tree_node*)
    ../.././gcc/stor-layout.c:2230
0xa0aaa3 build_array_type_1
    ../.././gcc/tree.c:7490
0x5add1f build_cplus_array_type(tree_node*, tree_node*)
    ../.././gcc/cp/tree.c:811
0x5af08e cp_build_qualified_type_real(tree_node*, int, int)
    ../.././gcc/cp/tree.c:1000
0x5bd2a0 canonicalize_for_substitution
    ../.././gcc/cp/mangle.c:364
0x5bd2a0 write_type
    ../.././gcc/cp/mangle.c:1886
0x5bd61d write_type
    ../.././gcc/cp/mangle.c:2052
0x5be6ff write_method_parms
    ../.././gcc/cp/mangle.c:2496
0x5be7fd write_bare_function_type
    ../.././gcc/cp/mangle.c:2438
0x5bbaff write_mangled_name
    ../.././gcc/cp/mangle.c:689
0x5c145d mangle_decl_string
    ../.././gcc/cp/mangle.c:3431
0x5c15d8 get_mangled_id
    ../.././gcc/cp/mangle.c:3453
0x5c15d8 mangle_decl(tree_node*)
    ../.././gcc/cp/mangle.c:3476
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

============================

It seems to be related to "my_int" being a typedef... if you change it to
#define my_int int

then it works fine.

Also, if I intentionally give it the wrong sort of array, then it gives the
correct error message and does not ICE, e.g. if I change the type to "const
double a[1] = {}" then i get:

t.cpp: In function 'int main()':
t.cpp:13:14: error: no matching function for call to 'f(const double [1])'
     f<void>(a);
              ^
t.cpp:13:14: note: candidate is:
t.cpp:9:6: note: template<class T> void f(const my_int (&)[X<T>::value])
 void f(const my_int(&)[X<T>::value]);
      ^
t.cpp:9:6: note:   template argument deduction/substitution failed:
t.cpp:13:14: note:   cannot convert 'a' (type 'const double [1]') to type
'const my_int (&)[1] {aka const int (&)[1]}'
     f<void>(a);

And similarly if I make the array the wrong size, larger than expected, it also
gives the correct error. But when the parameter matches, and the type in the
declaration of f is a typedef, then I get the ICE.

Thanks!

-lewis


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

* [Bug c++/62212] ICE compiling template function with array reference parameter whose size depends on a template parameter
  2014-08-20 20:54 [Bug c++/62212] New: ICE compiling template function with array reference parameter whose size depends on a template parameter lhyatt at gmail dot com
@ 2014-12-03 19:05 ` lhyatt at gmail dot com
  2015-05-07 15:52 ` lhyatt at gmail dot com
  2015-07-22 10:04 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: lhyatt at gmail dot com @ 2014-12-03 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Lewis Hyatt <lhyatt at gmail dot com> ---
Hello-

FYI this problem still exists on the mainline. I see the bug remains
unconfirmed, please let me know if more information would be useful, the
testcase was pretty simple so I just pasted it inline in the first report.
Thanks!

-Lewis


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

* [Bug c++/62212] ICE compiling template function with array reference parameter whose size depends on a template parameter
  2014-08-20 20:54 [Bug c++/62212] New: ICE compiling template function with array reference parameter whose size depends on a template parameter lhyatt at gmail dot com
  2014-12-03 19:05 ` [Bug c++/62212] " lhyatt at gmail dot com
@ 2015-05-07 15:52 ` lhyatt at gmail dot com
  2015-07-22 10:04 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: lhyatt at gmail dot com @ 2015-05-07 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Lewis Hyatt <lhyatt at gmail dot com> ---
Hello-

FYI, I have located the commit which broke this testcase, it is this one:

======================
Author: jason
Date: Fri Oct 15 21:15:13 2010
New Revision: 165521

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165521
Log:
        PR c++/45983
        * tree.c (cp_build_qualified_type_real): Don't reuse a variant
        with a different typedef variant of the element type.

Added:
    trunk/gcc/testsuite/g++.dg/lto/pr45983_0.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/ChangeLog
======================

Thanks...

-Lewis


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

* [Bug c++/62212] ICE compiling template function with array reference parameter whose size depends on a template parameter
  2014-08-20 20:54 [Bug c++/62212] New: ICE compiling template function with array reference parameter whose size depends on a template parameter lhyatt at gmail dot com
  2014-12-03 19:05 ` [Bug c++/62212] " lhyatt at gmail dot com
  2015-05-07 15:52 ` lhyatt at gmail dot com
@ 2015-07-22 10:04 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-07-22 10:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Let's CC Jason about his fix for c++/45983: apparently the comment "Tests
should be equivalent to those in check_qualified_type." isn't true anymore,
because the latter only compares the qualifiers.


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

end of thread, other threads:[~2015-07-22 10:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 20:54 [Bug c++/62212] New: ICE compiling template function with array reference parameter whose size depends on a template parameter lhyatt at gmail dot com
2014-12-03 19:05 ` [Bug c++/62212] " lhyatt at gmail dot com
2015-05-07 15:52 ` lhyatt at gmail dot com
2015-07-22 10:04 ` paolo.carlini at oracle dot com

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