[Bug c++/44743] New: Parser does not recogize local variable in constant expression for member function pointers

2010-07-01 Thread mschulze at ivs dot cs dot ovgu dot de
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() {}
};

templatetypename T, void (T::*fnc)()
void call(){
T t;
(t.*fnc)();
}

templatetypename T 
void deduce_type(void (T::*fnc)()){
callT,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

templatevoid (*f)()
void call(){
f();
}

templatetypename F
void deduce_type(void (*f)(), F){
callf();
}

# 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



[Bug c++/44743] Parser does not recogize local variable in constant expression for member function pointers

2010-07-01 Thread mschulze at ivs dot cs dot ovgu dot de


--- 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



[Bug c++/44577] New: static local variables in class template methods are not optimized-away if not used

2010-06-18 Thread mschulze at ivs dot cs dot ovgu dot de
IMO, in the following test program the variable s within the class template may
be optimized-away in every case. Although, the variable is used as an argument
for a function call, it is omit-able due to the definition of function t1 as
static inline with its empty body. If I use instead of a class template a
function template, this contained static local variable will be optimized-away,
as expected.

[mschu...@teeth tst]$ cat test.cc
static inline void t1(const char* s) {}

template typename T
struct class_template {
class_template() {
static const char s[]=class_template;
t1(s);
}
};

template typename T
static inline void function_template() {
static const char s[]=function_template;
t1(s);
}

int main(int, char**) {
class_templateint t;
function_templateint();
return 0;
}

I compiled the program with

[mschu...@teeth tst]$ 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)

and then I used the string program to list the contained strings.

[mschu...@teeth tst]$ strings t
/lib/ld-linux.so.2
libstdc++.so.6
__gmon_start__
_Jv_RegisterClasses
__gxx_personality_v0
libm.so.6
libgcc_s.so.1
libc.so.6
_IO_stdin_used
__libc_start_main
CXXABI_1.3
GLIBC_2.0
PTRhP
QVhD
[^_]
class_template
[mschu...@teeth tst]$

The class_template string is present, but the function_template string not. If
I omit the static keyword, it will disappear, too.



Thanks in advance,
Michael


-- 
   Summary: static local variables in class template methods are not
optimized-away if not used
   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=44577



[Bug c++/44577] static local variables in class template methods are not optimized-away if not used

2010-06-18 Thread mschulze at ivs dot cs dot ovgu dot de


--- Comment #1 from mschulze at ivs dot cs dot ovgu dot de  2010-06-18 
10:11 ---
(In reply to comment #0)
 IMO, in the following test program the variable s within the class template 
 may
 be optimized-away in every case. Although, the variable is used as an argument
 for a function call, it is omit-able due to the definition of function t1 as
 static inline with its empty body. If I use instead of a class template a
 function template, this contained static local variable will be 
 optimized-away,
 as expected.
 
 [mschu...@teeth tst]$ cat test.cc
 static inline void t1(const char* s) {}
 
 template typename T
 struct class_template {
 class_template() {
 static const char s[]=class_template;
 t1(s);
 }
 };
 
 template typename T
 static inline void function_template() {
 static const char s[]=function_template;
 t1(s);
 }
 
 int main(int, char**) {
 class_templateint t;
 function_templateint();
 return 0;
 }
 
 I compiled the program with
[mschu...@teeth tst]$ g++ -Wall -Ostest.cc -o t

 [mschu...@teeth tst]$ 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)
 
 and then I used the string program to list the contained strings.
 
 [mschu...@teeth tst]$ strings t
 /lib/ld-linux.so.2
 libstdc++.so.6
 __gmon_start__
 _Jv_RegisterClasses
 __gxx_personality_v0
 libm.so.6
 libgcc_s.so.1
 libc.so.6
 _IO_stdin_used
 __libc_start_main
 CXXABI_1.3
 GLIBC_2.0
 PTRhP
 QVhD
 [^_]
 class_template
 [mschu...@teeth tst]$
 
 The class_template string is present, but the function_template string not. If
 I omit the static keyword, it will disappear, too.
 
 
 
 Thanks in advance,
 Michael
 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44577



[Bug c++/44577] static local variables in class template methods are not optimized-away if not used

2010-06-18 Thread mschulze at ivs dot cs dot ovgu dot de


--- Comment #3 from mschulze at ivs dot cs dot ovgu dot de  2010-06-18 
12:01 ---
IMO, this is not a static member of a class itself, even it is defined inside
of a member function, thus I think it has not to have external linkage.


-- 

mschulze at ivs dot cs dot ovgu dot de changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44577



[Bug target/34734] attribute((progmem)) not handled properly in C++ for AVRs

2010-06-09 Thread mschulze at ivs dot cs dot ovgu dot de


--- Comment #4 from mschulze at ivs dot cs dot ovgu dot de  2010-06-09 
09:16 ---
I found a way to place data in program memory for C++ without producing the
annoying warnings. The trick is omiting __attribute__((__progmem__)) and
instead always use __attribute__((section(.progmem.something))) for placing
your data into a special section beginning with .progmem.. I tested this with
different avr-g++ compiler versions (3.4.4, 4.1.1, 4.2.1, 4.3.3, 4.4.0, and
4.4.3), and it always results in the desired behavior.

Example:
[mschu...@teeth tst]$ cat progmem.cpp 
static char __attribute((section(.progmem.something))) str[]=program memory
data;

const char* test() {
return str;
}
[mschu...@teeth tst]$ /usr/bin/avr-g++ -Wall -mmcu=atmega1281 -c progmem.cpp 
[mschu...@teeth tst]$ /usr/bin/avr-g++ --version
avr-g++ (GCC) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[mschu...@teeth tst]$ 

Regards,
Michael


-- 

mschulze at ivs dot cs dot ovgu dot de changed:

   What|Removed |Added

 CC||mschulze at ivs dot cs dot
   ||ovgu dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734