This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] libstdc++/1972 libstdc++/2089 fixes
- To: gcc-patches at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
- Subject: [v3] libstdc++/1972 libstdc++/2089 fixes
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Mon, 26 Feb 2001 20:11:49 -0800
fixes two bugs, libstdc++/1972 and libstdc++/2089
tested: x86/linux
in both branch and head
2001-02-26 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/1972
libstdc++/2089
* include/bits/std_stdexcept.h (logic_error::logic_error): Use
string object, not reference.
(runtime_error::runtime_error): Same.
* testsuite/19_diagnostics/stdexceptions.cc: New file.
Index: include/bits/std_stdexcept.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/std_stdexcept.h,v
retrieving revision 1.4
diff -c -p -r1.4 std_stdexcept.h
*** std_stdexcept.h 2001/02/19 18:52:25 1.4
--- std_stdexcept.h 2001/02/27 04:09:21
***************
*** 37,49 ****
#pragma GCC system_header
#include <exception>
! #include <bits/stringfwd.h>
namespace std
{
class logic_error : public exception
{
! const string& _M_msg;
public:
explicit
--- 37,49 ----
#pragma GCC system_header
#include <exception>
! #include <string>
namespace std
{
class logic_error : public exception
{
! const string _M_msg;
public:
explicit
*************** namespace std
*** 82,88 ****
class runtime_error : public exception
{
! const string& _M_msg;
public:
explicit
--- 82,88 ----
class runtime_error : public exception
{
! const string _M_msg;
public:
explicit
Index: testsuite/19_diagnostics/stdexceptions.cc
===================================================================
RCS file: stdexceptions.cc
diff -N stdexceptions.cc
*** /dev/null Tue May 5 13:32:27 1998
--- stdexceptions.cc Mon Feb 26 20:09:48 2001
***************
*** 0 ****
--- 1,80 ----
+ // 2001-02-26 Benjamin Kosnik <bkoz@redhat.com>
+
+ // Copyright (C) 2001 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library. This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ // GNU General Public License for more details.
+
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING. If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+
+ // 19.1 Exception classes
+
+ #include <string>
+ #include <stdexcept>
+ #include <debug_assert.h>
+
+ // libstdc++/1972
+ void test01()
+ {
+ bool test = true;
+ const char* strlit = "lack of sunlight, no water error";
+ // XXX work around long-standing, pathalogical, hostility-inducing parser bug
+ // std::logic_error obj(std::string(strlit));
+
+ // 1
+ std::logic_error obj = std::logic_error(std::string(strlit));
+
+ // 2
+ // std::logic_error obj((std::string)strlit);
+
+ VERIFY( strcmp(obj.what(), strlit) );
+ }
+
+ void test02()
+ {
+ bool test = true;
+ std::string s = "lack of sunlight error";
+ std::domain_error x(s);
+
+ VERIFY( strcmp(x.what(), s.data()) );
+ }
+
+ // libstdc++/2089
+ class fuzzy_logic : public std::logic_error
+ {
+ public:
+ fuzzy_logic() : std::logic_error("whoa") { }
+ };
+
+ void test03()
+ {
+ bool test = true;
+
+ try
+ { throw fuzzy_logic(); }
+ catch(const fuzzy_logic& obj)
+ { VERIFY( strcmp("whoa", obj.what()) ); }
+ catch(...)
+ { VERIFY( false ); }
+ }
+
+
+ int main(void)
+ {
+ test01();
+ test02();
+ test03();
+
+ return 0;
+ }