public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lhyatt at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/62212] New: ICE compiling template function with array reference parameter whose size depends on a template parameter
Date: Wed, 20 Aug 2014 20:54:00 -0000	[thread overview]
Message-ID: <bug-62212-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2014-08-20 20:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 20:54 lhyatt at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-62212-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).