[LLVMbugs] [Bug 19198] New: QoI: improve ios_base::failure implementation with specific error messages and codes

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Mar 19 12:43:39 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19198

            Bug ID: 19198
           Summary: QoI: improve ios_base::failure implementation with
                    specific error messages and codes
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: seth.cantrell at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

n3337 27.5.3.1.1 Class ios_base::failure [ios::failure] paragraph 2 reads:

When throwing ios_base::failure exceptions, implementations should provide
values of ec that identify the specific reason for the failure. [ Note: Errors
arising from the operating system would typically be reported as
system_category() errors with an error value of the error number reported by
the operating system. Errors arising from within the stream library would
typically be reported as error_code(io_errc::stream, iostream_category()). —end
note ]

Currently libc++ reports only a generic error. For example the following
program:

#include <iostream>
#include <fstream>
int main() {
  try {
    std::ifstream f("doesn't exist");
    f.exceptions(f.failbit);
  }
  catch (const std::ios_base::failure &e) {
    std::cerr << "Caught an ios_base::failure.\n"
              << "Explanatory string: " << e.what() << '\n'
              << "Error code: " << e.code() << '\n';
  }
}

Produces the output:

Caught an ios_base::failure.
Explanatory string: ios_base::clear: unspecified iostream_category error
Error code: iostream:1

Ideally it should produce output similar to that of the following program:

#include <iostream>
#include <cstdio>
int main() {
  FILE *f = fopen("doesn't exist", "r");
  if (!f) {
    std::cerr << "null FILE* returned.\n";
    perror("Explanatory string");
    std::cerr << "Error code: " << errno << '\n';
  }
}

which produces:

null FILE* returned.
Explanatory string: No such file or directory
Error code: 2

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140319/4a866da5/attachment.html>


More information about the llvm-bugs mailing list