brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 48a401e Raw
46 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// test logic_error10 11#include <stdexcept>12#include <type_traits>13#include <cstring>14#include <string>15#include <cassert>16 17#include "test_macros.h"18 19int main(int, char**)20{21    static_assert((std::is_base_of<std::exception, std::logic_error>::value),22                 "std::is_base_of<std::exception, std::logic_error>::value");23    static_assert(std::is_polymorphic<std::logic_error>::value,24                 "std::is_polymorphic<std::logic_error>::value");25    {26    const char* msg = "logic_error message";27    std::logic_error e(msg);28    assert(std::strcmp(e.what(), msg) == 0);29    std::logic_error e2(e);30    assert(std::strcmp(e2.what(), msg) == 0);31    e2 = e;32    assert(std::strcmp(e2.what(), msg) == 0);33    }34    {35    std::string msg("another logic_error message");36    std::logic_error e(msg);37    assert(e.what() == msg);38    std::logic_error e2(e);39    assert(e2.what() == msg);40    e2 = e;41    assert(e2.what() == msg);42    }43 44  return 0;45}46