Bug #4120

2 failures on test/mkmf/test_convertible.rb

Added by usa (Usaku NAKAMURA) over 1 year ago. Updated about 1 year ago.

[ruby-dev:42684]
Status:Closed Start date:12/06/2010
Priority:Normal Due date:
Assignee:nobu (Nobuyoshi Nakada) % Done:

100%

Category:lib
Target version:2.0.0
ruby -v:ruby 1.9.3dev (2010-12-06 trunk 30090) [x64-mswin64_100]

Description

表題のテストで、以下の2件の失敗が出ています。
なんかよくわからんので報告のみ。

  1) Failure:
test_typeof_builtin(TestMkmf::TestConvertible) [C:/Users/usa/ruby/test/mkmf/test_convertible.rb:8]:
<"long"> expected but was
<"int">.

  2) Failure:
test_typeof_typedef(TestMkmf::TestConvertible) [C:/Users/usa/ruby/test/mkmf/test_convertible.rb:21]:
<"long"> expected but was
<"int">.

Associated revisions

Revision 30107
Added by nobu (Nobuyoshi Nakada) over 1 year ago

* configure.in, win32/Makefile.sub (WERRORFLAG): flag to treat warnings as errors. * lib/mkmf.rb (Logging.postpone): yield log file object. * lib/mkmf.rb (xsystem): add options, :werror only right now. * lib/mkmf.rb (with_werror): check as if warnings are errors. * lib/mkmf.rb (convertible_int): make declaration conflict warnings errors not to pass wrong type. [ruby-dev:42684] * lib/mkmf.rb (COMMON_MACROS): get rid of conflicts. * win32/Makefile.sub (WARNFLAGS): make declaration conflict warnings errors if possible.

History

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

なかだです。

At Mon, 6 Dec 2010 11:11:12 +0900,
Usaku NAKAMURA wrote in [ruby-dev:42684]:
>   1) Failure:
> test_typeof_builtin(TestMkmf::TestConvertible) [C:/Users/usa/ruby/test/mkmf/test_convertible.rb:8]:
> <"long"> expected but was
> <"int">.
> 
>   2) Failure:
> test_typeof_typedef(TestMkmf::TestConvertible) [C:/Users/usa/ruby/test/mkmf/test_convertible.rb:21]:
> <"long"> expected but was
> <"int">.

VCでは以下のコードがエラーにならずに警告しか出ないからなのですが、何を
考えているんでしょうね。

  int foo();
  long foo();

  int bar(int);
  int bar(long);

longじゃなくてintとshortならちゃんとエラーになります。

-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

Updated by usa (Usaku NAKAMURA) over 1 year ago

こんにちは、なかむら(う)です。

In message "[ruby-dev:42688] Re: [Ruby 1.9-Bug#4120][Assigned] 2 failures on test/mkmf/test_convertible.rb"
    on Dec.06,2010 15:34:02, <nobu@ruby-lang.org> wrote:
> VCでは以下のコードがエラーにならずに警告しか出ないからなのですが、何を
> 考えているんでしょうね。

規格上これをエラーにしないといけないというルールはないような
気がするので[要確認]、普通に同じ幅なので警告で許してやろうと
いうことでしょうかねえ。

なので、だとしたら、これがエラーになることを利用する奴が悪い
ということになるんじゃないでしょうか。


それでは。
-- 
U.Nakamura <usa@garbagecollect.jp>

Updated by kosaki (Motohiro KOSAKI) over 1 year ago

2010年12月6日15:53 U.Nakamura <usa@garbagecollect.jp>:
> こんにちは、なかむら(う)です。
>
> In message "[ruby-dev:42688] Re: [Ruby 1.9-Bug#4120][Assigned] 2 failures on test/mkmf/test_convertible.rb"
>    on Dec.06,2010 15:34:02, <nobu@ruby-lang.org> wrote:
>> VCでは以下のコードがエラーにならずに警告しか出ないからなのですが、何を
>> 考えているんでしょうね。
>
> 規格上これをエラーにしないといけないというルールはないような
> 気がするので[要確認]、普通に同じ幅なので警告で許してやろうと
> いうことでしょうかねえ。

最近はC言語の規格もインターネットで閲覧できるんですね。インターネット万歳

http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

3.5 DECLARATIONS
(snip)
   All declarations in the same scope that refer to the same object or
function shall specify compatible types.

compatible typesの定義をみると

6.2.7 Compatible type and composite type

Two types have compatible type if their types are the same. Additional rules for
determining whether two types are compatible are described in 6.7.2
for type specifiers,
in 6.7.3 for type qualifiers, and in 6.7.5 for declarators.


なんか、基本厳密一致だけど詳細は type specifiersの章を見ろというのでみる

6.7.2 Type specifiers
Syntax
    type-specifier:
      void
      char
      short
      int
      long
      float
      double
      signed
      unsigned
      _Bool
      _Complex
      struct-or-union-specifier ∗
      enum-specifier
      typedef-name

Constraints
(snip)
the type specifiers may occur in any order, possibly
intermixed with the other declaration specifiers.

順序とか気にしなくていいよ。だそうな
適当に斜め読みしただけなので見落としてるかも知れませんがgccが正しそうな雰囲気。
JIS X3010 (ようするにC89)も見ましたが、同じように見えます。


>
> なので、だとしたら、これがエラーになることを利用する奴が悪い
> ということになるんじゃないでしょうか。

とはいえ、VCを無視するのは現実的ではないのでテストケース側を直すことに賛成します。

Updated by usa (Usaku NAKAMURA) over 1 year ago

こんにちは、なかむら(う)です。

In message "[ruby-dev:42694] Re: [Ruby 1.9-Bug#4120][Assigned] 2 failures on test/mkmf/test_convertible.rb"
    on Dec.06,2010 21:09:36, <kosaki.motohiro@gmail.com> wrote:
> >> VCでは以下のコードがエラーにならずに警告しか出ないからなのですが、何を
> >> 考えているんでしょうね。
> >
> > 規格上これをエラーにしないといけないというルールはないような
> > 気がするので[要確認]、普通に同じ幅なので警告で許してやろうと
> > いうことでしょうかねえ。
> 
> 最近はC言語の規格もインターネットで閲覧できるんですね。インターネット万歳
> 
> http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

実はその後自分でもC99眺めてたんですが、実際に矛盾が起きた時ど
うするかは Annex J.2 Undefined behavior の方にあります。
つまり、

  In a context requiring two function types to be compatible, they do not have
  compatible return types, or their parameters disagree in use of the ellipsis terminator
  or the number and type of parameters (after default argument promotion, when there
  is no parameter type list or when one type is specified by a function definition with an
  identifier list) (6.7.5.3).

の部分です。
というわけで、未定義動作のリストにこうやって挙げられているわ
けなので、矛盾する二つの関数宣言子が存在するコードがどのよう
に扱われるかは未定義です。鼻から悪魔。


> > なので、だとしたら、これがエラーになることを利用する奴が悪い
> > ということになるんじゃないでしょうか。

というわけで、悪いどころじゃなくて、宇宙が滅ぶかもしれないコ
ードを書いてそれを処理系に食わせるなんて信じられない!


> とはいえ、VCを無視するのは現実的ではないのでテストケース側を直すことに賛成します。

まあ、そう簡単にC処理系が宇宙を滅ぼしたりはしないと思うので、
実際に現状rubyがサポートしてる処理系ごとにどうなるのか情報を
集めて対応するしかないかなと思います。
さすがにエラーも出さなきゃ警告すらしない、という処理系はない
と信じたいので、警告かもしれないということを押さえさえすれば
大丈夫じゃないですかね。


それでは。
-- 
U.Nakamura <usa@garbagecollect.jp>

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r30107.
Usaku, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF