Forum: Ruby-dev [ruby-trunk - Bug #8674][Open] [patch] unused-parameter warning in ruby/ruby.h

Dea1add99f4cf942792c0f185aa2f2fd?d=identicon&s=25 Linda_pp (R H) (Guest)
on 2013-07-23 17:13
(Received via mailing list)
Issue #8674 has been reported by Linda_pp (R H).

----------------------------------------
Bug #8674: [patch] unused-parameter warning in ruby/ruby.h
https://bugs.ruby-lang.org/issues/8674

Author: Linda_pp (R H)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734)
[x86_64-darwin12.3.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


C++ のプログラムで ruby.h をインクルードすると ruby/ruby.h にて unused-parameter の警告が出ます.

・警告内容
In file included from
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby.h:33:0,
                 from ruby_interpreter.cpp:6:
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'filename' [-Wunused-parameter]
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'line' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'oldv' [-Wunused-parameter]
 rb_obj_written(VALUE a, VALUE oldv, VALUE b, const char *filename, int
line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'filename' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'line' [-Wunused-parameter]

・コンパイラ
 gcc 4.8.1

・コマンド
 g++ -Wall -Wextra -std=c++11 source.cpp

・環境
 MacOS X 10.8.4
Dea1add99f4cf942792c0f185aa2f2fd?d=identicon&s=25 Linda_pp (R H) (Guest)
on 2013-07-24 02:48
(Received via mailing list)
Issue #8674 has been updated by Linda_pp (R H).


`ruby -v` の出力が間違っていました。

ruby 2.1.0dev (2013-07-23 trunk) [x86_64-darwin12.3.0]

でした。失礼しました。
----------------------------------------
Bug #8674: [patch] unused-parameter warning in ruby/ruby.h
https://bugs.ruby-lang.org/issues/8674#change-40629

Author: Linda_pp (R H)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734)
[x86_64-darwin12.3.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


C++ のプログラムで ruby.h をインクルードすると ruby/ruby.h にて unused-parameter の警告が出ます.

・警告内容
In file included from
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby.h:33:0,
                 from ruby_interpreter.cpp:6:
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'filename' [-Wunused-parameter]
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'line' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'oldv' [-Wunused-parameter]
 rb_obj_written(VALUE a, VALUE oldv, VALUE b, const char *filename, int
line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'filename' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'line' [-Wunused-parameter]

・コンパイラ
 gcc 4.8.1

・コマンド
 g++ -Wall -Wextra -std=c++11 source.cpp

・環境
 MacOS X 10.8.4
308cbef6e86dfc49cce3b2d4cf42aedc?d=identicon&s=25 SASADA Koichi (Guest)
on 2013-07-24 04:03
(Received via mailing list)
使わないパラメータを残しているのは意図的なんですが、どうしたもんでしょ
う。マクロで使うときだけ有効にするような感じにするといいですかねぇ。
Dea1add99f4cf942792c0f185aa2f2fd?d=identicon&s=25 Linda_pp (R H) (Guest)
on 2013-07-24 07:40
(Received via mailing list)
Issue #8674 has been updated by Linda_pp (R H).


下記のように、パラメータを使用しない場合は警告を抑制するようにしてはいかがでしょうか。



*** ruby.h.old  2013-07-23 01:08:27.000000000 +0900
--- ruby.h  2013-07-23 23:57:01.000000000 +0900
***************
*** 1271,1276 ****
--- 1271,1279 ----
  {
  #ifdef RGENGC_LOGGING_WB_UNPROTECT
      RGENGC_LOGGING_WB_UNPROTECT(x, filename, line);
+ #else
+     (void)filename;
+     (void)line;
  #endif

  #if USE_RGENGC
***************
*** 1291,1296 ****
--- 1294,1303 ----
  {
  #ifdef RGENGC_LOGGING_OBJ_WRITTEN
      RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line);
+ #else
+     (void)oldv;
+     (void)filename;
+     (void)line;
  #endif

  #if USE_RGENGC

----------------------------------------
Bug #8674: [patch] unused-parameter warning in ruby/ruby.h
https://bugs.ruby-lang.org/issues/8674#change-40642

Author: Linda_pp (R H)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734)
[x86_64-darwin12.3.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


C++ のプログラムで ruby.h をインクルードすると ruby/ruby.h にて unused-parameter の警告が出ます.

・警告内容
In file included from
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby.h:33:0,
                 from ruby_interpreter.cpp:6:
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'filename' [-Wunused-parameter]
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'line' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'oldv' [-Wunused-parameter]
 rb_obj_written(VALUE a, VALUE oldv, VALUE b, const char *filename, int
line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'filename' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'line' [-Wunused-parameter]

・コンパイラ
 gcc 4.8.1

・コマンド
 g++ -Wall -Wextra -std=c++11 source.cpp

・環境
 MacOS X 10.8.4
9d2f78236e45a335301ba1195026105d?d=identicon&s=25 shyouhei (Shyouhei Urabe) (Guest)
on 2013-07-25 00:31
(Received via mailing list)
Issue #8674 has been updated by shyouhei (Shyouhei Urabe).


Linda_pp (R H) wrote:
> + #else
> +     (void)filename;
> +     (void)line;
>   #endif

(void)
で黙らせるのは感心しません。gccにおける警告の抑制が目的なら__attribute__((used))か__attribute__((unused))のどちらか適切な方を使うべきです。基本的に警告を黙らせる目的でキャスト使うのは邪悪です。避けるべきと思います。
----------------------------------------
Bug #8674: [patch] unused-parameter warning in ruby/ruby.h
https://bugs.ruby-lang.org/issues/8674#change-40655

Author: Linda_pp (R H)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734)
[x86_64-darwin12.3.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


C++ のプログラムで ruby.h をインクルードすると ruby/ruby.h にて unused-parameter の警告が出ます.

・警告内容
In file included from
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby.h:33:0,
                 from ruby_interpreter.cpp:6:
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'filename' [-Wunused-parameter]
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'line' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'oldv' [-Wunused-parameter]
 rb_obj_written(VALUE a, VALUE oldv, VALUE b, const char *filename, int
line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'filename' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'line' [-Wunused-parameter]

・コンパイラ
 gcc 4.8.1

・コマンド
 g++ -Wall -Wextra -std=c++11 source.cpp

・環境
 MacOS X 10.8.4
02da662c083396641da96c1d32fc86ed?d=identicon&s=25 KOSAKI Motohiro (Guest)
on 2013-07-25 19:08
(Received via mailing list)
(7/24/13 6:31 PM), shyouhei (Shyouhei Urabe) wrote:
> (void)
で黙らせるのは感心しません。gccにおける警告の抑制が目的なら__attribute__((used))か__attribute__((unused))のどちらか適切な方を使うべきです。基本的に警告を黙らせる目的でキャスト使うのは邪悪です。避けるべきと思います。
(void)で黙らせるのはあまりに広く普及しているので普通のコンパイラなら変なコード吐かないようにケアしてくれてると思うけどなあ。
ところでこれって、-Wunused-parameter 由来だから C++ じゃなくて
-Wextra由来だと思うんですが、なにか勘違いしてるかなあ。
-Wextraは false positive
てんこもりなのを許容しますよという宣言をコンパイラにしているのだから、つまらない警告でてもそういうものとしか思わないんだけど。
Eabad423977cfc6873b8f5df62b848a6?d=identicon&s=25 hsbt (Hiroshi SHIBATA) (Guest)
on 2013-11-29 11:37
(Received via mailing list)
Issue #8674 has been updated by hsbt (Hiroshi SHIBATA).

Status changed from Open to Feedback

>Linda_pp

shyouhei さんと kosaki さんのコメントに関して何か意見ありましたらお願いします。
----------------------------------------
Bug #8674: [patch] unused-parameter warning in ruby/ruby.h
https://bugs.ruby-lang.org/issues/8674#change-43253

Author: Linda_pp (Ryuichi Hayashida)
Status: Feedback
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734)
[x86_64-darwin12.3.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


C++ のプログラムで ruby.h をインクルードすると ruby/ruby.h にて unused-parameter の警告が出ます.

・警告内容
In file included from
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby.h:33:0,
                 from ruby_interpreter.cpp:6:
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'filename' [-Wunused-parameter]
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'line' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'oldv' [-Wunused-parameter]
 rb_obj_written(VALUE a, VALUE oldv, VALUE b, const char *filename, int
line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'filename' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'line' [-Wunused-parameter]

・コンパイラ
 gcc 4.8.1

・コマンド
 g++ -Wall -Wextra -std=c++11 source.cpp

・環境
 MacOS X 10.8.4
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-12-02 02:07
(Received via mailing list)
Issue #8674 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Feedback to Closed

Fixed at r43370.
----------------------------------------
Bug #8674: [patch] unused-parameter warning in ruby/ruby.h
https://bugs.ruby-lang.org/issues/8674#change-43328

Author: Linda_pp (Ryuichi Hayashida)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734)
[x86_64-darwin12.3.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


C++ のプログラムで ruby.h をインクルードすると ruby/ruby.h にて unused-parameter の警告が出ます.

・警告内容
In file included from
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby.h:33:0,
                 from ruby_interpreter.cpp:6:
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'filename' [-Wunused-parameter]
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1270:1:
warning: unused parameter 'line' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'oldv' [-Wunused-parameter]
 rb_obj_written(VALUE a, VALUE oldv, VALUE b, const char *filename, int
line)
 ^
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'filename' [-Wunused-parameter]
/Users/rhayasd/.rbenv/versions/2.1.0-dev/include/ruby-2.1.0/ruby/ruby.h:1290:1:
warning: unused parameter 'line' [-Wunused-parameter]

・コンパイラ
 gcc 4.8.1

・コマンド
 g++ -Wall -Wextra -std=c++11 source.cpp

・環境
 MacOS X 10.8.4
This topic is locked and can not be replied to.