[libc++] ios_base and exceptions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[libc++] ios_base and exceptions

Ben Pope
I think I've found a bug, what's the expected output of this program?

#include <sstream>
#include <iostream>

void test_iostate(std::ios_base::iostate state)
{
    char c;
    std::stringstream ss;
    try
    {
       ss.exceptions(state);
       ss >> c;
       std::cout << "Didn't throw\n";
    }
    catch(std::ios_base::failure const& ex)
    {
       std::cout << "Threw: " << ex.what() << "\n";
    }
}
int main()
{
    test_iostate(std::ios_base::eofbit);
    test_iostate(std::ios_base::badbit);
    test_iostate(std::ios_base::failbit);
    test_iostate(std::ios_base::eofbit|std::ios_base::badbit);
    test_iostate(std::ios_base::eofbit|std::ios_base::failbit);
    test_iostate(std::ios_base::badbit|std::ios_base::failbit);
 
test_iostate(std::ios_base::eofbit|std::ios_base::badbit|std::ios_base::failbit);
}


$ clang++ io_fail.cpp -stdlib=libc++ -lc++abi
$ ./a.out
Didn't throw
Didn't throw
Didn't throw
Threw: ios_base::clear: unspecified iostream_category error
Didn't throw
Threw: ios_base::clear: unspecified iostream_category error
Threw: ios_base::clear: unspecified iostream_category error

$ clang++ io_fail.cpp
$ ./a.out
Threw: basic_ios::clear
Didn't throw
Threw: basic_ios::clear
Threw: basic_ios::clear
Threw: basic_ios::clear
Threw: basic_ios::clear
Threw: basic_ios::clear

Ben

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [libc++] ios_base and exceptions

Marshall Clow

On Apr 22, 2014, at 8:23 AM, Ben Pope <[hidden email]> wrote:

> I think I've found a bug, what's the expected output of this program?

I think you’re right, Ben.
Please file a bug at:
        http://www.llvm.org/bugs

Feel free to assign it to me.

— Marshall

>
> #include <sstream>
> #include <iostream>
>
> void test_iostate(std::ios_base::iostate state)
> {
>   char c;
>   std::stringstream ss;
>   try
>   {
>      ss.exceptions(state);
>      ss >> c;
>      std::cout << "Didn't throw\n";
>   }
>   catch(std::ios_base::failure const& ex)
>   {
>      std::cout << "Threw: " << ex.what() << "\n";
>   }
> }
> int main()
> {
>   test_iostate(std::ios_base::eofbit);
>   test_iostate(std::ios_base::badbit);
>   test_iostate(std::ios_base::failbit);
>   test_iostate(std::ios_base::eofbit|std::ios_base::badbit);
>   test_iostate(std::ios_base::eofbit|std::ios_base::failbit);
>   test_iostate(std::ios_base::badbit|std::ios_base::failbit);
> test_iostate(std::ios_base::eofbit|std::ios_base::badbit|std::ios_base::failbit);
> }
>
>
> $ clang++ io_fail.cpp -stdlib=libc++ -lc++abi
> $ ./a.out
> Didn't throw
> Didn't throw
> Didn't throw
> Threw: ios_base::clear: unspecified iostream_category error
> Didn't throw
> Threw: ios_base::clear: unspecified iostream_category error
> Threw: ios_base::clear: unspecified iostream_category error
>
> $ clang++ io_fail.cpp
> $ ./a.out
> Threw: basic_ios::clear
> Didn't throw
> Threw: basic_ios::clear
> Threw: basic_ios::clear
> Threw: basic_ios::clear
> Threw: basic_ios::clear
> Threw: basic_ios::clear
>
> Ben
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [libc++] ios_base and exceptions

Ben Pope
On Wednesday, April 23, 2014 05:20 AM, Marshall Clow wrote:

>
> On Apr 22, 2014, at 8:23 AM, Ben Pope <[hidden email]> wrote:
>
>> I think I've found a bug, what's the expected output of this program?
>
> I think you’re right, Ben.
> Please file a bug at:
> http://www.llvm.org/bugs
>
> Feel free to assign it to me.

That does sound like a particularly dark corner. Apologies for the
misdirection.

Ben

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev