Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-998

add throw() exception specification to all non-throwing functions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: In Progress
    • Critical
    • Resolution: Unresolved
    • 4.2.1
    • 4.2.2
    • Build and Installation
    • None
    • Inefficiency

    Description

      When a compiler cannot determine whether a function declared without an explicit exception specification may throw an exception or not (e.g., because the compiler/optimizer doesn't have access to the definition of the function) it must assume that the function may throw and may need to generate suboptimal code as a result.

      Compilers often assume that even inline functions that can be proven not to throw exceptions may throw unless they are declared with the empty exception specification and generates suboptimal code as a result. For example, HP aCC 6 assumes that S::S() in the code below may throw
      and fails to optimize the catch block away, generating object code 2.5 times the size bigger than necessary. (Note that gcc 3.4 on IPF generates optimal code in this case).

      To help compilers generate optimal code we should make use of the empty exception specification on all functions that cannot throw exceptions, including those declared explicitly or implicitly inline.

      #include <new>
      
      struct S {
          int i;
          S () /* throw () */: i () { }
      };
      
      void uninit_fill (S *a, S *b)
      {
          S *p = a;
      
          try {
              for ( ; p != b; ++p)
                  new (p) S ();
          }
          catch (...) {
              while (p-- != a)
                  p->~S ();
              throw;
          }
      }
      

      Attachments

        1. unint_fill_nothrow.ipf.s
          5 kB
          Martin Sebor
        2. uninit_fill.ipf.s
          9 kB
          Martin Sebor

        Activity

          People

            sebor Martin Sebor
            sebor Martin Sebor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 6h
                6h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 6h
                6h