LCOV - code coverage report
Current view: top level - snapdev - not_reached.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 9 0.0 %
Date: 2023-05-29 16:11:08 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2011-2023  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdev
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software: you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation, either version 3 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License
      17             : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18             : #pragma once
      19             : 
      20             : /** \file
      21             :  * \brief Functions used for sanity checks.
      22             :  *
      23             :  * Often, we have points in our code that cannot be logically reached. By
      24             :  * adding the snapdev::NOT_REACHED() function call at those location, you
      25             :  * ensures that if somehow those are actually reached, then the program
      26             :  * terminates since it is not expected to go there.
      27             :  */
      28             : 
      29             : // libexcept
      30             : //
      31             : #include    <libexcept/exception.h>
      32             : 
      33             : 
      34             : // C++
      35             : //
      36             : #include    <iostream>
      37             : 
      38             : 
      39             : // C
      40             : //
      41             : #include    <stdlib.h>
      42             : 
      43             : 
      44             : 
      45             : namespace snapdev
      46             : {
      47             : 
      48             : [[noreturn]] [[deprecated]] inline void NOTREACHED()
      49             : {
      50             :     std::cerr << "NOT_REACHED called, process will abort." << std::endl;
      51             : 
      52             :     std::cerr << "Stack trace:" << std::endl;
      53             :     libexcept::stack_trace_t trace(libexcept::collect_stack_trace_with_line_numbers());
      54             :     for(auto l : trace)
      55             :     {
      56             :         std::cerr << "  " << l << std::endl;
      57             :     }
      58             : 
      59             :     abort();
      60             : }
      61             : 
      62           0 : [[noreturn]] inline void NOT_REACHED()
      63             : {
      64           0 :     std::cerr << "NOT_REACHED called, process will abort." << std::endl;
      65             : 
      66           0 :     std::cerr << "Stack trace:" << std::endl;
      67           0 :     libexcept::stack_trace_t trace(libexcept::collect_stack_trace_with_line_numbers());
      68           0 :     for(auto l : trace)
      69             :     {
      70           0 :         std::cerr << "  " << l << std::endl;
      71           0 :     }
      72             : 
      73           0 :     abort();
      74           0 : }
      75             : 
      76             : } // namespace snapdev
      77             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14