Bug 42338 - [c++0x] ICE on decltype usage with templates
Summary: [c++0x] ICE on decltype usage with templates
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.2
: P3 major
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-08 23:37 UTC by Onay Urfalioglu
Modified: 2010-02-09 22:30 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-01-20 22:42:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Onay Urfalioglu 2009-12-08 23:37:16 UTC
The following code causes an ICE with segmentation fault:
----------------------------------------------------------------------
#include <iostream>
#include <vector>

template< typename T1 >
void vadd(const std::vector< T1 > &a, decltype(a[0]) t) {
    std::cout << "-> ICE \n";
}
void vadd(const std::vector< int > &a, decltype(a[0]) t) {
    std::cout << " compiles \n";
}


int main() {
    std::vector< int > a;
    std::vector< float > b;
    int c;
    vadd(b,c); // leads to ICE
//     vadd(a,c); // compiles
}
----------------------------------------------------------------------
Output of 
"g++ -v -save-temps   gcc-error-src.cpp -o gcc-error -std=c++0x"
yields:

Using built-in specs.                                                                                                                                                                                                                         
Target: x86_64-linux-gnu                                                                                                                                                                                                                      
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.2-3' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu                                                                                             
Thread model: posix                                                                                                                                                                                                                           
gcc version 4.4.2 (Debian 4.4.2-3)                                                                                                                                                                                                            
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'gcc-error' '-std=c++0x' '-shared-libgcc' '-mtune=generic'                                                                                                                                        
 /usr/lib/gcc/x86_64-linux-gnu/4.4.2/cc1plus -E -quiet -v -D_GNU_SOURCE gcc-error-src.cpp -mtune=generic -std=c++0x -fpch-preprocess -o gcc-error-src.ii                                                                                      
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"                                                                                                                                                                          
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.2/../../../../x86_64-linux-gnu/include"                                                                                                                                     
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"                                                                                                                                                                                
#include "..." search starts here:                                                                                                                                                                                                            
#include <...> search starts here:                                                                                                                                                                                                            
 /usr/include/c++/4.4                                                                                                                                                                                                                         
 /usr/include/c++/4.4/x86_64-linux-gnu                                                                                                                                                                                                        
 /usr/include/c++/4.4/backward                                                                                                                                                                                                                
 /usr/local/include                                                                                                                                                                                                                           
 /usr/lib/gcc/x86_64-linux-gnu/4.4.2/include                                                                                                                                                                                                  
 /usr/lib/gcc/x86_64-linux-gnu/4.4.2/include-fixed                                                                                                                                                                                            
 /usr/include                                                                                                                                                                                                                                 
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'gcc-error' '-std=c++0x' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/x86_64-linux-gnu/4.4.2/cc1plus -fpreprocessed gcc-error-src.ii -quiet -dumpbase gcc-error-src.cpp -mtune=generic -auxbase gcc-error-src -std=c++0x -version -o gcc-error-src.s
GNU C++ (Debian 4.4.2-3) version 4.4.2 (x86_64-linux-gnu)
        compiled by GNU C version 4.4.2, GMP version 4.3.1, MPFR version 2.4.1-p2.
warning: MPFR header version 2.4.1-p2 differs from library version 2.4.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 76c61736f716d7c937923f7eb86174cd
gcc-error-src.cpp:19: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.4/README.Bugs> for instructions.
Comment 1 Paolo Carlini 2009-12-09 09:50:30 UTC
Jason, the ICE happens in mangle.c, write_expression gets a null argument. Is this another variant of c++/38600 and the likes?
Comment 2 Jonathan Wakely 2009-12-18 00:42:06 UTC
I suspect this is the same issue, as it also passes a null argument to write_expression

$ cat ice.cc
template<typename T>
auto f(T t) -> decltype(++t, 0)
{
    ++t;
    return 0;
}

int main()
{
    f((int*)0);
}
$ ~/gcc/4.x/bin/g++ -std=c++0x ice.cc
ice.cc: In instantiation of 'decltype (((++ t), 0)) f(T) [with T = int*, decltype (((++ t), 0)) = int]':
ice.cc:10:14:   instantiated from here
ice.cc:6:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 3 Jason Merrill 2010-01-21 01:59:13 UTC
Subject: Bug 42338

Author: jason
Date: Thu Jan 21 01:58:53 2010
New Revision: 156103

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156103
Log:
	PR c++/42338
	* mangle.c (write_expression): Handle tree codes that have extra
	arguments in the middle-end.
	* cp-demangle.c (d_print_comp): Fix array index printing.

Added:
    trunk/gcc/testsuite/g++.dg/abi/mangle39.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/mangle.c
    trunk/libiberty/ChangeLog
    trunk/libiberty/cp-demangle.c

Comment 4 Paolo Carlini 2010-01-21 10:17:15 UTC
Thus, Jason, it turns out this is *not* a duplicate of c++/38600, doesn't have to do with mangling template_id_expr, right? By the way, if you have got two spare minutes, could you maybe add something about the latter in that audit trail? Duplicates are coming and coming, I'm afraid people (myself included ;) are a bit confused about why we cannot mangle that.
Comment 5 Jason Merrill 2010-02-09 22:30:59 UTC
Fixed.