public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers
@ 2010-07-01 12:37 mschulze at ivs dot cs dot ovgu dot de
2010-07-01 12:47 ` [Bug c++/44743] " redi at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: mschulze at ivs dot cs dot ovgu dot de @ 2010-07-01 12:37 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2777 bytes --]
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<typename T, void (T::*fnc)()>
void call(){
T t;
(t.*fnc)();
}
template<typename T >
void deduce_type(void (T::*fnc)()){
call<T,fnc>();
}
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 (*f)()>
void call(){
f();
}
template<typename F>
void deduce_type(void (*f)(), F){
call<f>();
}
# 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/44743] Parser does not recogize local variable in constant expression for member function pointers
2010-07-01 12:37 [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers mschulze at ivs dot cs dot ovgu dot de
@ 2010-07-01 12:47 ` redi at gcc dot gnu dot org
2010-07-01 12:57 ` mschulze at ivs dot cs dot ovgu dot de
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-07-01 12:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from redi at gcc dot gnu dot org 2010-07-01 12:47 -------
works as expected in 4.4.3 and later
$ g++ temp.cc
temp.cc: In function 'void deduce_type(void (T::*)()) [with T = A]':
temp.cc:17: instantiated from here
temp.cc:13: error: 'fnc' is not a valid template argument for type 'void
(A::*)()'
temp.cc:13: error: it must be a pointer-to-member of the form `&X::Y'
temp.cc:13: error: no matching function for call to 'call()'
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44743
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/44743] Parser does not recogize local variable in constant expression for member function pointers
2010-07-01 12:37 [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers mschulze at ivs dot cs dot ovgu dot de
2010-07-01 12:47 ` [Bug c++/44743] " redi at gcc dot gnu dot org
@ 2010-07-01 12:57 ` mschulze at ivs dot cs dot ovgu dot de
2010-07-01 13:11 ` redi at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mschulze at ivs dot cs dot ovgu dot de @ 2010-07-01 12:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from mschulze at ivs dot cs dot ovgu dot de 2010-07-01 12:57 -------
However, the error message is little bit misleading, because fnc is exactly of
the requested type but it is a local variable, IMO.
The question is, is the code standard conform or not?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44743
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/44743] Parser does not recogize local variable in constant expression for member function pointers
2010-07-01 12:37 [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers mschulze at ivs dot cs dot ovgu dot de
2010-07-01 12:47 ` [Bug c++/44743] " redi at gcc dot gnu dot org
2010-07-01 12:57 ` mschulze at ivs dot cs dot ovgu dot de
@ 2010-07-01 13:11 ` redi at gcc dot gnu dot org
2010-07-01 13:29 ` redi at gcc dot gnu dot org
2010-07-24 18:20 ` [Bug c++/44743] Parser does not recognize " pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-07-01 13:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from redi at gcc dot gnu dot org 2010-07-01 13:11 -------
(In reply to comment #2)
> However, the error message is little bit misleading, because fnc is exactly of
> the requested type but it is a local variable, IMO.
True, the reason it's not allowed is because it's not a constant.
> The question is, is the code standard conform or not?
Not.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44743
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/44743] Parser does not recogize local variable in constant expression for member function pointers
2010-07-01 12:37 [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers mschulze at ivs dot cs dot ovgu dot de
` (2 preceding siblings ...)
2010-07-01 13:11 ` redi at gcc dot gnu dot org
@ 2010-07-01 13:29 ` redi at gcc dot gnu dot org
2010-07-24 18:20 ` [Bug c++/44743] Parser does not recognize " pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-07-01 13:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from redi at gcc dot gnu dot org 2010-07-01 13:29 -------
Note that the error isn't saying the type is wrong, it says it must be of the
form `&X::Y' which is a constant expression and is different to a variable with
the same value as &X::Y
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44743
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/44743] Parser does not recognize local variable in constant expression for member function pointers
2010-07-01 12:37 [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers mschulze at ivs dot cs dot ovgu dot de
` (3 preceding siblings ...)
2010-07-01 13:29 ` redi at gcc dot gnu dot org
@ 2010-07-24 18:20 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-24 18:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2010-07-24 18:20 -------
*** This bug has been marked as a duplicate of 37093 ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44743
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-07-24 18:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-01 12:37 [Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers mschulze at ivs dot cs dot ovgu dot de
2010-07-01 12:47 ` [Bug c++/44743] " redi at gcc dot gnu dot org
2010-07-01 12:57 ` mschulze at ivs dot cs dot ovgu dot de
2010-07-01 13:11 ` redi at gcc dot gnu dot org
2010-07-01 13:29 ` redi at gcc dot gnu dot org
2010-07-24 18:20 ` [Bug c++/44743] Parser does not recognize " pinskia at gcc dot gnu dot org
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).