Bug 39070 - [4.3/4.4 regression] ICE with typeof() (... and __decltype)
Summary: [4.3/4.4 regression] ICE with typeof() (... and __decltype)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.3
: P3 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2009-02-01 21:17 UTC by Roman Kononov
Modified: 2009-02-14 05:42 UTC (History)
3 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-02-13 03:01:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roman Kononov 2009-02-01 21:17:04 UTC
$ cat test.cpp
template<typename X> struct junk {
   template<typename Y> static Y& y();
   template<typename Y> char test(typeof(y<Y>().foo())*);
   static int const value=sizeof(test<X>(0));
};
int function() { int const v=junk<int>::value; };

$ g++ -c -v test.cpp
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /home/rk/xdisw/base/gnutools/gcc-4.3.3/configure --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++ --enable-werror
Thread model: posix
gcc version 4.3.3 (GCC)
COLLECT_GCC_OPTIONS='-c' '-v' '-shared-libgcc' '-mtune=generic'
 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.3.3/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -auxbase test -version -o /tmp/ccn9FvNk.s
ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.3.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.3.3/../../../../include/c++/4.3.3
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.3.3/../../../../include/c++/4.3.3/x86_64-unknown-linux-gnu
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.3.3/../../../../include/c++/4.3.3/backward
 /usr/local/include
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.3.3/include
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.3.3/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.3.3 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.3.3, GMP version 4.2.4, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f44867537d1291d59450732603599474
test.cpp: In instantiation of 'const int junk<int>::value':
test.cpp:7:   instantiated from here
test.cpp:4: 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.

$ uname -a
Linux wata 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 11:57:43 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
Comment 1 Andrew Pinski 2009-02-06 01:37:54 UTC
I don't get a segfault on the trunk but I do get an error message:
t.cc: In instantiation of 'const int junk<int>::value':
t.cc:6:   instantiated from here
t.cc:4: error: no matching function for call to 'junk<int>::test(int)'

Comment 2 Wolfgang Bangerth 2009-02-12 23:21:01 UTC
I do get an ICE:

g/x> /home/bangerth/bin/x86/gcc-mainline/bin/c++ -c x.cc
x.cc: In instantiation of 'const int junk<int>::value':
x.cc:6:   instantiated from here
x.cc:4: 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.


g/x> /home/bangerth/bin/x86/gcc-mainline/bin/c++ -v     
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../mainline/configure --enable-languages=c,c++ --enable-checking --with-mpfr=/home/bangerth/bin/x86 --with-gmp=/home/bangerth/bin/x86 --prefix=/home/bangerth/bin/x86/gcc-mainline
Thread model: posix
gcc version 4.4.0 20090211 (experimental) [trunk revision 144104] (GCC) 


The code is invalid, of course.
W.
Comment 3 Roman Kononov 2009-02-12 23:49:11 UTC
$ cat t.cc
template<typename X> struct junk {
   template<typename Z> static Z& y();
   template<typename Y> static int  test(...);
   template<typename Y> static char test(typeof(y<Y>())*);
   static int const value=sizeof(test<X>(0));
};
typedef char type[junk<int>::value==sizeof(char) ? 1 : -1];

g++ 4.3.2 is happy with the above code.
g++ 4.3.3 gives a segfault.
Comment 4 Wolfgang Bangerth 2009-02-13 00:12:38 UTC
Confirmed, it also ICEs on mainline.

That's a much more serious case. I'm not entirely sure whether the code
is valid: you do

   template<typename Z> static Z& y();
   template<typename Y> static char test(typeof(y<Y>())*);

with Y=int, i.e. the argument to test() would be of type
  typeof(int&)*
or pointer-to-reference, which is not valid. One may argue that if template
substitution fails that the second overload of test should be chosen, though:
   template<typename Y> static int  test(...);

Since typeof is not part of the C++ standard, I doubt that anything
normative is available for this case.

Regardless of the validity of the testcase, since it used to work before
and now no longer does I would appreciate more eyes on it.

W.
Comment 5 Paolo Carlini 2009-02-13 00:19:04 UTC
... and by the way, ICEs also with __decltype...
Comment 6 H.J. Lu 2009-02-13 02:37:30 UTC
It is caused by revision 143422:

http://gcc.gnu.org/ml/gcc-cvs/2009-01/msg00435.html
Comment 7 Jason Merrill 2009-02-13 19:14:28 UTC
Subject: Bug 39070

Author: jason
Date: Fri Feb 13 19:14:07 2009
New Revision: 144161

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144161
Log:
        PR c++/39070
        * semantics.c (finish_call_expr): Change koenig_p parm to int.
        If -1, don't set KOENIG_LOOKUP_P but do keep hidden candidates.
        * cp-tree.h: Adjust prototype.
        * pt.c (tsubst_copy_and_build) [CALL_EXPR]: Pass -1.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/decltype16.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Jason Merrill 2009-02-13 21:53:56 UTC
Subject: Bug 39070

Author: jason
Date: Fri Feb 13 21:53:38 2009
New Revision: 144166

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144166
Log:
        PR c++/39070
        * semantics.c (finish_call_expr): Change koenig_p parm to int.
        If -1, don't set KOENIG_LOOKUP_P but do keep hidden candidates.
        * cp-tree.h: Adjust prototype.
        * pt.c (tsubst_copy_and_build) [CALL_EXPR]: Pass -1.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/cpp0x/decltype16.C
      - copied unchanged from r144161, trunk/gcc/testsuite/g++.dg/cpp0x/decltype16.C
Modified:
    branches/gcc-4_3-branch/gcc/cp/ChangeLog
    branches/gcc-4_3-branch/gcc/cp/cp-tree.h
    branches/gcc-4_3-branch/gcc/cp/pt.c
    branches/gcc-4_3-branch/gcc/cp/semantics.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 9 Jason Merrill 2009-02-14 05:42:21 UTC
Fixed in 4.3 and 4.4.