From: Naohisa Goto Date: 2009-09-18T20:49:32+09:00 Subject: [ruby-dev:39350] [Bug #2118] SUN の cc (SunStudio11 C 5.8 コンパイラ) で dir.c のコンパイルに失敗する Bug #2118: SUN の cc (SunStudio11 C 5.8 コンパイラ) で dir.c のコンパイルに失敗する http://redmine.ruby-lang.org/issues/show/2118 起票者: Naohisa Goto ステータス: Open, 優先度: Normal ruby -v: ruby 1.9.2dev (2009-09-18) [sparc-solaris2.10] Solaris10 上の Sun Studio 11 C 5.8 コンパイラにて trunk r25000 の コンパイルに失敗します。 $ ./configure --prefix=/XXXXX/testruby/sparc/trunk-25000_64cc \ MAKE=/usr/local/64/bin/make \ CC=/opt/SUNWspro/bin/cc \ CXX=/opt/SUNWspro/bin/CC \ CFLAGS="-xarch=v9 -xtarget=native64 -I/usr/local/64/include" \ LDSHARED="/opt/SUNWspro/bin/cc -G" \ LDFLAGS="-xarch=v9 -xtarget=native64 -L/usr/local/64/lib -R/usr/local/64/lib" $ /usr/local/64/bin/make (中略) /opt/SUNWspro/bin/cc -xarch=v9 -xtarget=native64 -I/usr/local/64/include -I. -I.ext/include/sparc-solaris2.10 -I./include -I. -DRUBY_EXPORT -o dir.o -c dir.c "./include/ruby/ruby.h", line 958: warning: implicit function declaration: rb_type "dir.c", line 394: operands have incompatible types: void ":" unsigned long "dir.c", line 394: operands have incompatible types: volatile unsigned long ":" void "dir.c", line 1632: operands have incompatible types: void ":" unsigned long "dir.c", line 1632: operands have incompatible types: volatile unsigned long ":" void "dir.c", line 1662: operands have incompatible types: void ":" unsigned long "dir.c", line 1662: operands have incompatible types: volatile unsigned long ":" void cc: acomp failed for dir.c make: *** [dir.o] Error 2 Warningはいったんは無視して、エラーに着目すると、 "dir.c", line 394: operands have incompatible types: void ":" unsigned long が発生している行の内容は、 GlobPathValue(dirname, FALSE); です。これはマクロで、 #define GlobPathValue(str, safe) \ /* can contain null bytes as separators */ \ (!RB_TYPE_P(str, T_STRING) ? \ FilePathValue(str) : \ (safe) ? rb_check_safe_obj(str) : (str)) のように3項演算子を使用していて、 この中で rb_check_safe_obj(str) が void を返す関数のため、 3項演算子内で型に互換性がないというエラーを出しているようです。 以下のように「,」を使って値 0 を返すようにしたらコンパイルは通りました。 rb_check_safe_obj(str) を囲む()は不要かもしれませんが念のため入れました。 =================================================================== --- dir.c (revision 25000) +++ dir.c (working copy) @@ -343,7 +343,7 @@ /* can contain null bytes as separators */ \ (!RB_TYPE_P(str, T_STRING) ? \ FilePathValue(str) : \ - (safe) ? rb_check_safe_obj(str) : (str)) + (safe) ? ((rb_check_safe_obj(str)),0) : (str)) static VALUE dir_s_alloc(VALUE klass) =================================================================== "./include/ruby/ruby.h", line 958: warning: implicit function declaration: rb_type は今のところ gcc 以外の場合にのみ出る warning のようで、 rb_type のプロトタイプ宣言を TYPE() が使われる前に入れれば消えました。 =================================================================== --- include/ruby/ruby.h (revision 25000) +++ include/ruby/ruby.h (working copy) @@ -952,6 +952,7 @@ #ifdef __GNUC__ # define NUM2CHR(x) ({VALUE num2chr_x = (x); NUM2CHR_internal(num2chr_x);}) #else +static inline int rb_type(VALUE); static inline char NUM2CHR(VALUE x) { =================================================================== ---------------------------------------- http://redmine.ruby-lang.org