diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2001-02-27 04:13:17 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2001-02-27 04:13:17 +0000 |
commit | 0349df29f030a533d0a0dfd1b2db491a49b05436 (patch) | |
tree | 31e71f34a373d06d13ee94e113871c4ae6fc8a13 | |
parent | 8bb3dc7766c027a46f0345c4f9c291b42178a903 (diff) | |
download | gcc-0349df29f030a533d0a0dfd1b2db491a49b05436.zip gcc-0349df29f030a533d0a0dfd1b2db491a49b05436.tar.gz gcc-0349df29f030a533d0a0dfd1b2db491a49b05436.tar.bz2 |
std_stdexcept.h (logic_error::logic_error): Use string object, not reference.
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.
From-SVN: r40079
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/std_stdexcept.h | 6 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/19_diagnostics/stdexceptions.cc | 80 |
3 files changed, 92 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cdf6a9c..8a4302c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +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. + 2001-02-26 Phil Edwards <pme@sources.redhat.com> * acinclude.m4 (GLIBCPP_CONFIGURE): Update required compiler version. diff --git a/libstdc++-v3/include/bits/std_stdexcept.h b/libstdc++-v3/include/bits/std_stdexcept.h index b354487..dc503aa 100644 --- a/libstdc++-v3/include/bits/std_stdexcept.h +++ b/libstdc++-v3/include/bits/std_stdexcept.h @@ -37,13 +37,13 @@ #pragma GCC system_header #include <exception> -#include <bits/stringfwd.h> +#include <string> namespace std { class logic_error : public exception { - const string& _M_msg; + const string _M_msg; public: explicit @@ -82,7 +82,7 @@ namespace std class runtime_error : public exception { - const string& _M_msg; + const string _M_msg; public: explicit diff --git a/libstdc++-v3/testsuite/19_diagnostics/stdexceptions.cc b/libstdc++-v3/testsuite/19_diagnostics/stdexceptions.cc new file mode 100644 index 0000000..ac56b59 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/stdexceptions.cc @@ -0,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; +} |