[cfe-dev] Odd clang result using stringstream formatted input
Edward Diener via cfe-dev
cfe-dev at lists.llvm.org
Mon Oct 31 14:30:32 PDT 2016
On 10/31/2016 1:05 PM, Reid Kleckner via cfe-dev wrote:
> Seems like a mingw-ish bug. This program works as expected in an MSVC
> environment. I don't have a 32-bit mingw installation to reproduce your
> configuration.
It's my error. The std::ios_base::failure exception is derived from
std::runtime_error only for c++11. In VC++ c++11 mode is automaically on
whereas in clang the default is c++03 mode.
>
> On Thu, Oct 27, 2016 at 2:41 AM, Edward Diener via cfe-dev
> <cfe-dev at lists.llvm.org
> <mailto: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 ?
More information about the cfe-dev
mailing list