From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27204 invoked by alias); 1 Jul 2010 12:37:56 -0000 Received: (qmail 27129 invoked by uid 48); 1 Jul 2010 12:37:38 -0000 Date: Thu, 01 Jul 2010 12:37:00 -0000 Subject: [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "mschulze at ivs dot cs dot ovgu dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg00057.txt.bz2 The parser does not reject invalid code, but instead passes to the compiler. The compiler fails with different internal compiler errors depending on the optimization level. With levels -O2, -O3 and -Os, the compiler generates valid object code without complaining anything. How to reproduce? # cat ice.cc struct A { inline void foo() {} }; template void call(){ T t; (t.*fnc)(); } template void deduce_type(void (T::*fnc)()){ call(); } int main() { deduce_type(&A::foo); return 0; } # g++ ICE.cc -o ICE -Wall ICE.cc: In function ‘void call() [with T = A, void (T::* fnc)() = fnc]’: ICE.cc:8: internal compiler error: in expand_expr_real_1, at expr.c:7314 # g++ ICE.cc -o ICE -Wall -O1 ICE.cc: In function ‘void call() [with T = A, void (T::* fnc)() = fnc]’: ICE.cc:6: internal compiler error: in make_decl_rtl, at varasm.c:1290 # g++ ICE.cc -o ICE -Wall -O2 If we use instead of a member function pointer a usual function pointer like in the following code snippet template void call(){ f(); } template void deduce_type(void (*f)(), F){ call(); } # g++ -c ICE2.cc -o ICE2.o -Wall ICE2.cc: In function ‘void deduce_type(void (*)(), F)’: ICE2.cc:24: error: ‘f’ cannot appear in a constant-expression ICE2.cc:24: error: no matching function for call to ‘call()’ # g++ -v Using built-in specs. Target: i586-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i586 --build=i586-redhat-linux Thread model: posix gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC) -- Summary: Parser does not recogize local variable in constant expression for member function pointers Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mschulze at ivs dot cs dot ovgu dot de GCC build triplet: i586-redhat-linux GCC host triplet: i586-redhat-linux GCC target triplet: i586-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44743