[cfe-dev] Odd clang result using stringstream formatted input

Michał Górny via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 27 02:49:58 PDT 2016


On Thu, 27 Oct 2016 05:41:12 -0400
Edward Diener via cfe-dev <cfe-dev at lists.llvm.org> wrote:

> The following program:
> 
> #include <iostream>
> #include <sstream>
> #include <stdexcept>
> int main()
>      {
> 	
>      std::stringstream ss;
>      ss.exceptions(std::ios_base::failbit | std::ios_base::badbit);
>      char c;
> 
>      try
>          {
>          ss >> c;
>          std::cout << "Exception not thrown.";
>          }
>      catch (std::runtime_error &)
>          {
>          std::cout << "Exception std::runtime_error thrown.";
>          }
>      catch (...)
>          {
>          std::cout << "Unknown exception thrown.";
>          }
>      }
> 
> outputs "Unknown exception thrown." when compiled and linked with the 
> latest clang built from source on Windows 7. The compilation options are:
> 
> -c -x c++ -Wno-unused-local-typedef -Wno-dll-attribute-on-redeclaration 
> -O0 -g -fno-inline -Wall -g -march=i686 -m32 -o
> 
> The linker options are:
> 
> -Wl,-Bstatic  -Wl,-Bdynamic  -Wl,--end-group -g -march=i686 -m32
> 
> I would have expected the output to be "Exception std::runtime_error 
> thrown." as it is when compiled with VC++ 14.
> 
> Is clang following the C++ standard or is this a bug in clang ?

I can't reproduce this on Linux with libc++, using quite recent SVN
versions.

1. Could you try with -std=c++11? Looking at [1], that particular
inheritance is specific to C++11 and newer.

2. Which clang version are you using?

[1]:http://en.cppreference.com/w/cpp/io/ios_base/failure

-- 
Best regards,
Michał Górny
<http://dev.gentoo.org/~mgorny/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 931 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161027/357fb013/attachment.sig>


More information about the cfe-dev mailing list