Realized that SouceLocation and ScopeTracker can never be no-throw scopetracker-nothrow
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 4 Sep 2018 09:29:07 +0000 (11:29 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 4 Sep 2018 09:29:07 +0000 (11:29 +0200)
Constructors can always throw if the class has non-pointer attributes
(at least I think so). So would have to re-design SourceLocation and
ScopeTracker to only contain pointers in order to make SCOPETRACKER
guaranteed no-throw.

src/source_track_basics.cpp
src/source_track_basics.hpp
src/tracefunc.hpp

index 9f8f470..4985570 100644 (file)
@@ -35,23 +35,48 @@ namespace I2n
 
 /*
 ** implementation of SourceLocation
+ *
+ * Failed to really make this no-throw. Even in this form, class attributes File and FunctionName need to have
+ * some value which takes up memory space, so PCLINT rightly complains that exception '...' thrown from string
+ * construction is not on throw-list.
+ *
+ * To really guarantee a no-throw constructor, would have to only have pointers that can be set to NULL if
+ * something fails.
 */
 
 SourceLocation::SourceLocation() throw ()
-: Line ( 0 )
 {
+    try
+    {
+        File = "";
+        Line = 0;
+        FunctionName = "";
+        LocationTag = "";
+    }
+    catch(...)
+    {
+        ;  // do nothing
+    }
 } // eo SourceLocation::SourceLocation()
 
 
 SourceLocation::SourceLocation (
     const std::string& file,
-    long line,
+    const long& line,
     const std::string& funcname
 ) throw ()
-: File( file )
-, Line( line )
-, FunctionName( funcname )
 {
+    try
+    {
+        File = file;
+        Line = line;
+        FunctionName = funcname;
+        LocationTag = "";
+    }
+    catch(...)
+    {
+        ;  // do nothing
+    }
 } // eo SourceLocation::SourceLocation(const std::string&,long,const std::string&)
 
 
index ad18cb8..0946ab2 100644 (file)
@@ -56,17 +56,17 @@ struct SourceLocation
 
    SourceLocation(
       const std::string& file,
-      long  line,
+      const long&  line,
       const std::string& funcname) throw ();
 
-   operator bool() const throw ()
+   operator bool() const
    {
       return Line>0 and not File.empty() and not FunctionName.empty();
    } // eo operator bool
 
-   std::string get_function_name() const throw () { return FunctionName; }
-   std::string get_filename()      const throw () { return File; }
-   long        get_line_number()   const throw () { return Line; }
+   std::string get_function_name() const { return FunctionName; }
+   std::string get_filename()      const { return File; }
+   long        get_line_number()   const { return Line; }
 
    std::string get_location_tag() const;
 
index 36a6227..cf5475e 100644 (file)
@@ -45,8 +45,7 @@ class PerThreadContainer;
  * basically: emits a ENTER message on construction and a LEAVE message on destruction.
  * And indent these messages acoording to the nesting depth.
  *
- * If something goes wrong nothing is thrown from constructor/destructor. Will try to
- * log only that some problem occurred.
+ * Tried to avoid any throw from constructor/destructor but failed
  */
 class ScopeTracker
 {
@@ -75,6 +74,8 @@ class ScopeTracker
 
 /**
  * @brief constructs a scope tracker.
+ *
+ * Would have like to make this guaranteed no-throw, but failed.
  */
 #define SCOPETRACKER() ::I2n::Tracer::ScopeTracker __scope_tracker(HERE)