Closed Bug 884022 Opened 11 years ago Closed 11 years ago

Clang build fails in test_AsXXX_helpers.cpp (comparison between pointer and integer)

Categories

(Core :: General, defect)

x86_64
macOS
defect
Not set
blocker

Tracking

()

RESOLVED FIXED
mozilla24
Tracking Status
firefox22 --- wontfix
firefox23 --- wontfix
firefox24 --- fixed
b2g18 --- fixed
b2g18-v1.0.0 --- wontfix
b2g18-v1.0.1 --- wontfix
b2g-v1.1hd --- fixed

People

(Reporter: jruderman, Assigned: ehsan.akhgari)

References

Details

Attachments

(1 file, 1 obsolete file)

With a fairly recent clang (llvm svn 184056), the build fails in test_AsXXX_helpers.cpp.

Daniel Holbert and Nathan Froyd looked a little bit on IRC.  They suspect the fix for bug 787730 was incorrect.

/Users/jruderman/trees/mozilla-central/storage/test/test_AsXXX_helpers.cpp:39:3: error: comparison between pointer and integer
      ('const char *' and 'int')
  do_check_eq(row->AsSharedUTF8String(0, &len), '\0');
  ^           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~

/Users/jruderman/trees/mozilla-central/storage/test/storage_test_harness.h:66:19: note: expanded from macro 'do_check_eq'
    if (aExpected == aActual) { \
                  ^
Blocks: 787730
No longer depends on: 784776, 787730
Attached patch Patch (v1) (obsolete) — Splinter Review
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Attachment #763779 - Flags: review?(dholbert)
Comment on attachment 763779 [details] [diff] [review]
Patch (v1)

Nope, this reintroduces the problem bug 787730 was trying to fix.

/Users/jruderman/trees/mozilla-central/storage/test/test_AsXXX_helpers.cpp:39:3: error: use of overloaded operator '<<' is ambiguous (with operand types 'std::ostringstream'
      (aka 'basic_ostringstream<char>') and 'nullptr_t')
  do_check_eq(row->AsSharedUTF8String(0, &len), nullptr);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jruderman/trees/mozilla-central/storage/test/storage_test_harness.h:71:12: note: expanded from macro 'do_check_eq'
      temp << aActual <<"' at line " << __LINE__; \
      ~~~~ ^
/usr/include/c++/4.2.1/ostream:112:7: note: candidate function
      operator<<(__ostream_type& (*__pf)(__ostream_type&))
      ^
/usr/include/c++/4.2.1/ostream:121:7: note: candidate function
      operator<<(__ios_type& (*__pf)(__ios_type&))
      ^
Attachment #763779 - Flags: feedback-
Maybe it would be better to use do_check_true, or introduce a do_check_null.

http://mxr.mozilla.org/mozilla-central/source/storage/test/storage_test_harness.h#26
We can cast nullptr to the correct type or we can use do_check_false.  I went with
the first solution.
Attachment #763779 - Attachment is obsolete: true
Attachment #763779 - Flags: review?(dholbert)
Attachment #763794 - Flags: review?(dholbert)
Ah, you're using an old libstdc++... :(
Comment on attachment 763794 [details] [diff] [review]
fix clang warnings about pointer-to-int comparisons with test_AsXXX_helpers.cpp

I'd prefer static_cast<>, since this is C++, but it doesn't matter too much.
Attachment #763794 - Flags: review?(dholbert) → review+
For int, I guess this is ok.  But for char, (const char *) is another way of saying "C string".  What happens if you try to send a nullptr C string to an iostream?
https://hg.mozilla.org/mozilla-central/rev/f53918bafe2a
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
(In reply to comment #7)
> For int, I guess this is ok.  But for char, (const char *) is another way of
> saying "C string".  What happens if you try to send a nullptr C string to an
> iostream?

You get no output?
From some quick googling, it looks like the behavior of cout << (const char*)NULL might be undefined, which does seem problematic.

That's how the test was written, though, AFAICT; this bug didn't impact that at all. If you're worried about that, take it up with the test author. :)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: